Custom exception page in Asp.net

Source: Internet
Author: User
Sort by exception handling priority
(0) AddCode
Protected void application_error (Object sender, eventargs E)
{
Context. clearerror ();
Response. Write ("error ");
Response. Redirect ("errorpage.htm ");
}
(1) webform1_error in the background code
Add the exception handling code to the error event of UI. Page in the properties of the aspx page.
Private void webform1_error (Object sender, system. eventargs E)
{
Exception EX = server. getlasterror ();
Session ["error"] = ex. message;
Server. clearerror ();
Response. Redirect ("error. aspx ");
}
(2) Add errorpage to HTML code
Errorpage = "http://www.21cn.com"
(3) add an exception handling page in Web. config
<Customerrors mode = "on" defaultredirect = "error. aspx">
<Error statuscode = "401" Redirect = "error. aspx"/>
<Error statuscode = "404" Redirect = "http://www.sina.com.cn"/>
</Customerrors>
(4) set the exception handling page in IIS
Related Article

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.