本文介绍了如何设置环境名称(IHostingEnvironment.EnvironmentName)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
默认的ASP.NET Core Web项目在Startup.cs
中包含以下行:
Default ASP.NET Core web project contain such lines in Startup.cs
:
if (string.Equals(env.EnvironmentName, "Development", StringComparison.OrdinalIgnoreCase))
{
app.UseBrowserLink();
app.UseDeveloperExceptionPage(ErrorPageOptions.ShowAll);
}
else
{
app.UseExceptionHandler("/Home/Error");
}
据我了解,EnvironmentName是处理Dev/Production环境的新方法.但这在Release构建配置上没有改变.那么设置不同的EnvironmentName
的方法是什么?
As I understand, the EnvironmentName is a new way to handle Dev/Production environment. But it doesn't changes on Release build configuration. So what is the way to set a different EnvironmentName
?
我可以想象应该在命令"中将其设置为服务器的参数.
I can imagine that it should be set in "Commands" as a parameter for server.
推荐答案
launchsettings.json
在属性"> launchsettings.json
At Properties > launchsettings.json
就像这样:
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:1032/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Production"
}
},
"WebAppNetCore": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"web": {
"commandName": "web",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
这篇关于如何设置环境名称(IHostingEnvironment.EnvironmentName)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!