【发布时间】:2022-10-18 22:46:41
【问题描述】:
我可以右键单击 --> 将 .NET core Razor 应用程序发布到具有不同发布配置文件的远程 IIS 服务器,但是当发布配置文件中的 EnvironmentName 设置为 Development 时,我只能看到开发人员异常...
<PropertyGroup>
<EnvironmentName>Development</EnvironmentName>
</PropertyGroup>
否则我会看到:
Development Mode
Swapping to the Development environment displays detailed information about the error that occurred.
The Development environment shouldn't be enabled for deployed applications. It can result in displaying sensitive information from exceptions to end users. For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development and restarting the app.
有没有办法将环境名称更改为自定义名称并仍然看到开发人员异常?我在这里https://learn.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-3.1#environments 发现提到了env.IsDevelopment(),但我不确定我是否可以使用它,或者在什么文件中。我希望能够使用多个 appSettings 文件,例如appsettings.Azure_dev.json,并且仍然可以看到开发人员异常。谢谢!
编辑...我最终做了什么:
我在 appsettings.json 中为我的项目列出了有效的开发环境
"Deploy_Settings": {
"Dev_Environments": "Development;Azure_Dev"
},
并对照它们检查环境名称
List<string> listDevEnvs = new List<string>(configuration.GetSection("Deploy_Settings")["Dev_Environments"].Split(new char[] { ';' }));
string CurrEnvName = app.Environment.EnvironmentName;
// This is to show Developer Exception errors in deployments with Environment names other than 'Development'
if (listDevEnvs.Contains(CurrEnvName))
{
app.UseDeveloperExceptionPage();
}
【问题讨论】:
标签: visual-studio .net-core msbuild