如何设置IHostingEnvironment.EnvironmentName在vNext应用程序? [英] How to set IHostingEnvironment.EnvironmentName in vNext application?
问题描述
默认vNext Web项目包含这样的行 Startup.cs
:
如果(string.Equals(env.EnvironmentName,发展,StringComparison.OrdinalIgnoreCase))
{
app.UseBrowserLink();
app.UseErrorPage(ErrorPageOptions.ShowAll);
}
其他
{
app.UseErrorHandler(/首页/错误);
}
据我了解,在EnvironmentName是处理开发/生产环境的新途径。但它确实在发布版本的配置不能更改。那么,什么是设置方式不同 EnvironmentName
?
我可以想像,它应该在命令被设置为服务器的参数。
我可以想像,它应该在命令被设置为服务器的参数。
块引用>这才是真正的。在你project.json,添加
- ASPNET_ENV生产
为服务器的参数project.json
命令:{
网络:Microsoft.AspNet.Hosting --ASPNET_ENV生产--server Microsoft.AspNet.Server.WebListener --server.urls的http://本地主机:5001
}现在,当您运行
DNX。网络
在命令行中,ASPNET_ENV
将制作
。天青
我们也不能在Azure的WEB设置APP>配置>应用程序设置区域。
Default vNext web project contain such lines in
Startup.cs
:if (string.Equals(env.EnvironmentName, "Development", StringComparison.OrdinalIgnoreCase)) { app.UseBrowserLink(); app.UseErrorPage(ErrorPageOptions.ShowAll); } else { app.UseErrorHandler("/Home/Error"); }
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.
解决方案I can imagine that it should be set in "Commands" as a parameter for server.
That is true. In your project.json, add
--ASPNET_ENV production
as a parameter for the server.project.json
"commands": { "web": "Microsoft.AspNet.Hosting --ASPNET_ENV production --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5001" }
Now when you run
dnx . web
from the command line,ASPNET_ENV
will beproduction
.Azure
We cannot also set in from the Azure WEB APP > CONFIGURE > app settings area.
这篇关于如何设置IHostingEnvironment.EnvironmentName在vNext应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!