相关疑难解决方法(0)

如何在ASP.NET Core中的任何类中访问Configuration?

我已经完成了ASP.NET核心的配置文档.文档说您可以从应用程序的任何位置访问配置.

下面是模板创建的Startup.cs

public class Startup
{
    public Startup(IHostingEnvironment env)
    {
        var builder = new ConfigurationBuilder()
            .SetBasePath(env.ContentRootPath)
            .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
            .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);

        if (env.IsEnvironment("Development"))
        {
            // This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately.
            builder.AddApplicationInsightsSettings(developerMode: true);
        }

        builder.AddEnvironmentVariables();
        Configuration = builder.Build();
    }

    public IConfigurationRoot Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container
    public void ConfigureServices(IServiceCollection …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-core-mvc asp.net-core

102
推荐指数
7
解决办法
8万
查看次数

标签 统计

asp.net-core ×1

asp.net-core-mvc ×1

c# ×1