如何设置IHostingEnvironment.EnvironmentName在vNext应用程序?

编程入门 行业动态 更新时间:2024-10-18 12:21:10
本文介绍了如何设置IHostingEnvironment.EnvironmentName在vNext应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

默认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 localhost:5001" }

Now when you run dnx . web from the command line, ASPNET_ENV will be production.

Azure

We cannot also set in from the Azure WEB APP > CONFIGURE > app settings area.

更多推荐

如何设置IHostingEnvironment.EnvironmentName在vNext应用程序?

本文发布于:2023-11-08 07:27:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1568726.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   如何设置   EnvironmentName   IHostingEnvironment   vNext

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!