DataProtection/WebApp01/Controllers/EnvironmentController.cs

(完整代码) 1KB

namespace WebApp01.Controllers
{
    using System.Collections.Generic;

    using Microsoft.AspNetCore.Mvc;
    using Microsoft.Extensions.Configuration;
    using Microsoft.Extensions.Options;

    using Newtonsoft.Json;

    using WebApp01.Options;

    [ApiController]
    [Route("[controller]")]
    public class EnvironmentController : ControllerBase
    {
        private readonly IOptions<TestOption> testOption;

        public EnvironmentController(IOptions<TestOption> testOption)
        {
            this.testOption = testOption;
        }

        [HttpGet]
        public IActionResult GetEnvironmentVariables()
        {
            Dictionary<string, string> dicts = new Dictionary<string, string>();
            ConfigurationBuilder builder = new ConfigurationBuilder();
            builder.AddJsonFile("appsettings.json");
            IConfigurationRoot configuration = builder.Build();

            dicts.Add("ProtectionOption.Thumbprint", configuration.GetSection("ProtectionOption:Thumbprint").Value);
            dicts.Add("ProtectionOption.ApplicationName", configuration.GetSection("ProtectionOption:ApplicationName").Value);
            dicts.Add("ProtectionOption.SecretKeyPath", configuration.GetSection("ProtectionOption:SecretKeyPath").Value);
            dicts.Add("ProtectionOption.Purpose", configuration.GetSection("ProtectionOption:Purpose").Value);
            dicts.Add("TestOption.Test1", testOption.Value.Test1);
            dicts.Add("TestOption.Test2", testOption.Value.Test2);
            dicts.Add("DataBase.DbConnection", configuration.GetSection("DataBase:DbConnection").Value);

            return Ok(JsonConvert.SerializeObject(dicts));
        }
    }
}

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。