如何设置环境名称 (IHostingEnvironment.EnvironmentName)?

编程入门 行业动态 更新时间:2024-10-18 19:25:03
本文介绍了如何设置环境名称 (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 是一种处理开发/生产环境的新方法.但它不会在发布构建配置上发生变化.那么如何设置不同的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": "localhost:1032/", "sslPort": 0 } }, "profiles": { "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Production" } }, "WebAppNetCore": { "commandName": "Project", "launchBrowser": true, "launchUrl": "localhost:5000", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }, "web": { "commandName": "web", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } } } }

更多推荐

如何设置环境名称 (IHostingEnvironment.EnvironmentName)?

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

发布评论

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

>www.elefans.com

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