本文介绍了如何设置环境名称 (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)?
发布评论