s.k.paul
s.k.paul

Reputation: 7301

web.config in ASP.NET Core 2

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?

Sorry if this a foolish question.

Upvotes: 2

Views: 5419

Answers (1)

David Liang
David Liang

Reputation: 21536

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.

Upvotes: 5

Related Questions