0
votes

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
The problem is that when the error handling is being configured in Startup, there is no active request, and as such, there's no way to determine whether it's "remote" or not. You'd likely need to create some sort of custom middleware for this, but that's far beyond the scope of Stack Overflow. You'll need to do your own research and attempt a solution on your own first. - Chris Pratt
That's right. We cant have a check like Request.IsLocal = true in startup.Thanks! - Rohit Bhardwaj

1 Answers

0
votes

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.