I have an AspNet Core web application, in which I want to show custom errors only when someone is accessing the application remotely. In case this application is being accessed locally ,i want to keep the detailed error page for the developer. In .netFramework 4.x and earlier, we were able to specify this in web.config customErrors property with mode=RemoteOnly. I am aware about the fact that we can make user of ASPNETCORE_ENVIRONMENT variable to turn on custom error or developer exception page in aspnetcore. But what I am looking for is -to have similar functionality for CustomErrors mode = RemoteOnly in AspNetCore.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
To answer your question directly, I don't believe there is an straight forward replacement for CustomErrors key in the Web.config. However, there are a few more methods available on the IHostingEnvironment interface that may be of use for you depending on what you're trying to implement. For example you could check multiple environments:
if (env.IsProduction() || env.IsStaging() || env.IsEnvironment("Staging_2"))
{
// Handle the custom errors here
}
There is decent documentation on different ways to implement environment specific features here.