I just started learning ASP.NET Core 2 MVC application.
After taking a new project, I don\'t see any web.config file in solution explorer.
Any help?
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:
{
"Recaptcha": {
"SiteKey": "xxxx-xxxx",
"SecretKey": "xxxx-xxxx"
}
}
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.