ASP.NET Core 2中的web.config

时间:2018-05-15 05:50:23

标签: web-config asp.net-core-2.0

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

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

有任何帮助吗?

对不起,如果这是一个愚蠢的问题。

1 个答案:

答案 0 :(得分:5)

web.config不再使用Asp.Net Core,即使Startup.cs不再使用它。

配置现在是appsettings.json中应用程序启动过程的一部分。还有一个名为{ "Recaptcha": { "SiteKey": "xxxx-xxxx", "SecretKey": "xxxx-xxxx" } } 的应用程序设置文件,您可以在其中放置所有配置值。

您可以阅读如下设置值:

appsettings.json

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")
       });
    }
}

Startup.cs

.Net Core

同样在.csproj项目中,有Edit <project>.csproj个文件。您可以右键单击项目,然后单击web.config

发布Web项目后,将生成

body{ background: #DDD; } span{ margin-left: 30px; } input[type=checkbox] { cursor: pointer; font-size: 17px; visibility: hidden; position: absolute; top: 0; left: 0; transform: scale(1.5); } input[type=checkbox]:after { content: " "; background-color: #fff; display: inline-block; color: #00BFF0; width: 14px; height: 19px; visibility: visible; border: 1px solid #FFF; padding: 0 3px; margin: 2px 0; border-radius: 8px; box-shadow: 0 0 15px 0 rgba(0,0,0,0.08), 0 0 2px 0 rgba(0,0,0,0.16); } input[type=checkbox]:checked:after { content: "\2714"; display: unset; font-weight: bold; }

相关问题