ASP.NET Core 2中的web.config [英] web.config in ASP.NET Core 2

查看:258
本文介绍了ASP.NET Core 2中的web.config的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始学习ASP.NET Core 2 MVC应用程序.

I just started learning ASP.NET Core 2 MVC application.

完成新项目后,在解决方案资源管理器中看不到任何web.config文件.

After taking a new project, I don't see any web.config file in solution explorer.

有帮助吗?

抱歉,这是一个愚蠢的问题.

Sorry if this a foolish question.

推荐答案

不仅Asp.Net Core 2.x不再使用web.config,甚至Asp.Net Core也不再使用它.

Not just Asp.Net Core 2.x no longer uses web.config, even the Asp.Net Core no longer uses it.

现在,该配置是应用程序启动过程的一部分,在Startup.cs中.还有一个名为appsettings.json的应用程序设置文件,您可以在其中放置所有配置值.

The configuration now is part of the application startup procedure, in Startup.cs. And there is an application setting file called appsettings.json where you can put all your configuration values there.

您可以读取以下设置值:

You can read setting values like this:

{
    "Recaptcha": {
        "SiteKey": "xxxx-xxxx",
        "SecretKey": "xxxx-xxxx"
    }
}

Startup.cs

public class Startup
{
    public IConfiguration Configuration { get; private set; }

    public Startup(IConfiguration configuration)
    {
        this.Configuration = configuration;
    }

    public void ConfigureServices(IServiceCollection services)
    {
       ...

       // Configure Google Recaptcha
       // reading values from appsettings.json
       services.AddRecaptcha(new RecaptchaOptions
       {
           SiteKey = this.Configuration.GetValue<string>("Recaptcha:SiteKey"),
           SecretKey = this.Configuration.GetValue<string>("Recaptcha:SecretKey")
       });
    }
}

.Net Core项目中也有.csproj文件.您可以右键单击一个项目,然后单击Edit <project>.csproj.

Also in .Net Core projects, there is .csproj file. You can right click a project and click Edit <project>.csproj.

web.config.

这篇关于ASP.NET Core 2中的web.config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆