s.k*_*aul 2 web-config asp.net-core-2.0
我刚刚开始学习ASP.NET Core 2 MVC应用程序。
接受新项目后,在解决方案资源管理器中看不到任何web.config文件。
有什么帮助吗?
抱歉,这是一个愚蠢的问题。
不仅Asp.Net Core 2.x不再使用web.config,甚至Asp.Net Core不再使用它。
现在,该配置是应用程序启动过程的一部分,在中Startup.cs。还有一个名为的应用程序设置文件appsettings.json,您可以在其中放置所有配置值。
您可以像这样读取设置值:
{
"Recaptcha": {
"SiteKey": "xxxx-xxxx",
"SecretKey": "xxxx-xxxx"
}
}
Run Code Online (Sandbox Code Playgroud)
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")
});
}
}
Run Code Online (Sandbox Code Playgroud)
在.Net Core项目中也有.csproj文件。您可以右键单击一个项目,然后单击确定Edit <project>.csproj。
web.config 将在您发布Web项目后生成。
| 归档时间: |
|
| 查看次数: |
3879 次 |
| 最近记录: |