An Improvement on the exception handling solution (also on the limitations of IE)

Source: Internet
Author: User

The previous article explains how to capture and handle website exceptions. After several days of use, I suddenly found a problem, that is, sometimes I cannot display the correct error page in IE, but the IE error page that usually appears in the network terminal:

The same error page is displayed in Firefox, which is consistent with the design expectation:

The following is the processing result after an exception is caught in the system.Code:

1 Public   Static   Void Showerror ( String Errmsg)
2 {
3 String Localerr =   " An error occurred during execution. The error message is: " ;
4 If (Errmsg =   Null )
5 Localerr + =   " None " ;
6 Else
7 Localerr + = Errmsg;
8
9 Localerr = Httpcontext. Current. server. urlencode (localerr );
10 Httpcontext. Current. response. Redirect ( String . Format ( " ~ /Showerror. aspx? Errstring = '{0 }' " , Localerr ), True );
11 Httpcontext. Current. response. End ();
12 }

Seeing the code snippet above, I think some friends with rich web development experience have seen the problem. Yes, here, the error message is added to the URL and passed to the error page, but the length of the string supported by the IE address bar is very limited! I tried it myself. I can only enter no more than 2048 English characters in the address bar of IE7. According to Microsoft's introduction, there should be 2083 characters. In short, the difference is not big. In fact, for the response. Redirect ($ URL) method, we used to know that using it is equivalent to re-requesting $ URL from the client, but thought it is only "equivalent", but it is actually a direct jump on the server. However, by passing an excessively long error string to the response in IE shown in $ URL, the request is actually re-sent from the client. Once you know the problem, it is easy to solve it. just modify the above Code as follows:

1 Public   Static   Void Showerror ( String Errmsg)
2 {
3 String Localerr =   " An error occurred during execution. The error message is: " ;
4 If (Errmsg =   Null )
5 Localerr + =   " None " ;
6 Else
7 Localerr + = Errmsg;
8
9 String Errpagesource =   String . Format (errorpagetemplate, localerr );
10 Httpcontext. Current. response. Write (errpagesource );
11 }
12

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.