开发者

Redirect on Error - ASP.NET

I understand that I can redirect a user on an exception by setting the customErrors elemen开发者_Python百科t 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?


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜