Asp.net custom simple error handling page

Source: Internet
Author: User

Web ApplicationsProgramAfter the release, in order to give the user a friendly interface and user experience, the user will jump to a custom error page when an error occurs, rather than the detailed exception list exposed to the user by Asp.net.

The simple error handling page can be set through web. config.

<Customerrors Mode= "Remoteonly" Defaultredirect= "Genericerrorpage.htm"><Error Statuscode= "403" Redirect= "Noaccess.htm" /><Error Statuscode= "404" Redirect= "Filenotfound.htm" /></Customerrors>
 
 

If you want to program the cause of the error, you can use the page_error event. you can use global. I think this method is more convenient to implement with asax. In addition, it seems more comfortable to combine a separate and more friendly page.

Global. asax(If necessary, you can record the error log)

VoidApplication_error (ObjectSender, eventargs e) {exception objerr = server. getlasterror (). getbaseexception ();StringError ="Exception page :"+ Request. url. tostring () +"<Br>"; Error + ="Exception information :"+ Objerr. Message +"<Br>"; Server. clearerror (); application ["Error"] = Error; response. Redirect ("~ /Errorpage. aspx");}
 
 

Errorpage. aspx

 
Protected VoidPage_load (ObjectSender, eventargs e) {errormessagelabel. Text = application ["Error"]. Tostring ();}


When end users use applications, they may not want to know the cause of the error. In this case, we can use the check box to check whether the cause of the error is displayed. You can place the label in a div and use the check box to determine whether to render the div.

  

We can make some more friendly designs on the errorpage to make people look more comfortable. Pai_^

 

Permanent address: http://www.cnblogs.com/yoshow/archive/2007/01/18/623404.html

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.