Not just Asp.Net Core 2.x
no longer uses web.config
, even the Asp.Net Core
no longer uses it.
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:
appsettings.json
{
"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")
});
}
}
Also in .Net Core
projects, there is .csproj
file. You can right click a project and click Edit <project>.csproj
.
web.config
will be generated after you publish your web projects.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…