Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
198 views
in Technique[技术] by (71.8m points)

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...