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