Alternate for CustomErrors Mode = “RemoteOnly” in

2019-08-18 05:21发布

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条回答
放我归山
2楼-- · 2019-08-18 05:41

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.

查看更多
登录 后发表回答