Nick
Nick

Reputation: 7525

Redirect on Error - ASP.NET

I understand that I can redirect a user on an exception by setting the customErrors element in the Web.config

<customErrors mode="On" defaultRedirect="/WebTest/ErrorPages/AppError.html">
</customErrors>

I could also do a Response.Redirect in the Application_Error event in the Global.asax file.

What are the differences between these 2 approaches and which one is preferred?

Upvotes: 1

Views: 441

Answers (2)

Mehrdad Afshari
Mehrdad Afshari

Reputation: 422242

If you don't want to do anything with the error (such as logging), you'd better simply use the configuration file. It's simpler and easier to reconfigure. Moreover, using the configuration file has the advantage of supporting RemoteOnly type, where you can easily see the exception on the server for diagnostics purposes but others won't be able to see it.

In general, there's no point in writing code for something that's perfectly configurable and is built in the system. Code is more prone to errors than configuration options.

Upvotes: 5

Jonathan Bates
Jonathan Bates

Reputation: 1835

I am not sure of anything official, but I find using the config file easier for local testing versus production behaviour.

Upvotes: 0

Related Questions