开发者

Redirecting user to dynamic error page

开发者 https://www.devze.com 2022-12-21 19:07 出处:网络
Can I configure ASP.NET custom errors so that it would redirect to other site when error has occurred. Even more, I would like to redirect to different web page every time.

Can I configure ASP.NET custom errors so that it would redirect to other site when error has occurred. Even more, I would like to redirect to different web page every time.

Here is my simplified actual case:

User opens my pages with query ?urlpage=http:/开发者_开发知识库/test.com/error.html and I would like to redirect to this page when error occurs.

How should I act in this scenario?


See http://msdn.microsoft.com/en-us/library/ed577840.aspx

And in the Page_Error method, just do:

var redirectUrl = Request.QueryString["urlpage"];
if (redirectUrl != null)
   Response.Redirect(redirectUrl);


There are a number of different resources in ASP.NET that will allow you to handle errors.

I found this article on the web.config file very informative : http://articles.sitepoint.com/article/web-config-file-demystified

In addition you can setup error handling inside of the global.asax file that will trap application wide errors and allow you to send emails, log information, etc.

You can also setup page specific error handling for more custom error information - but I find that a good general purpose error handling in global.asax works for most situations.

Finally, you can go into the properties for IIS and modify where errors are redirected. For instance, set the 500 error to point to a specific file (/error.aspx or similar).

0

精彩评论

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

关注公众号