本文介绍了如何设置IHostingEnvironment.EnvironmentName在vNext应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认vNext Web项目包含这样的行 Startup.cs

 如果(string.Equals(env.EnvironmentName,发展,StringComparison.OrdinalIgnoreCase))
{
    app.UseBrowserLink();
    app.UseErrorPage(ErrorPageOptions.ShowAll);
}
其他
{
    app.UseErrorHandler(/首页/错误);
}

据我了解,在EnvironmentName是处理开发/生产环境的新途径。但它确实在发布版本的配置不能更改。那么,什么是设置方式不同 EnvironmentName

我可以想像,它应该在命令被设置为服务器的参数。


解决方案

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 be production.

Azure

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

这篇关于如何设置IHostingEnvironment.EnvironmentName在vNext应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 08:32