ASP. NET Unhandled exception

Source: Internet
Author: User
Tags urlencode

  1. Page-level Catch Unhandled Exception-page Error event
    1     Protected Sub Page_Error (ByVal asObjectByValasHandlesMe  . Error2         Response.Redirect ("errorinfo.aspx? errmsg=unhandled&detail=" & System.Web.HttpUtility.UrlEncode ( Server.GetLastError.ToString))3     End Sub

    Write the processing logic in the page's Error event handler Page_Error.

  2. Page-level Capture Unhandled Exception-page's ErrorPage property
    1     Protected Sub Page_Load (ByValasObjectByValasHandlesMe. Load2         Me"errorinfo.aspx" 3     End Sub

    To make the ErrorPage property effective requires that mode in customerrors be set to on

    in Web. config

     1  <  configuration  >  2   >  3  <  customerrors  mode  = "on"  />  4  </ system.web  >  5  </ configuration  >  

    3. Application-level Catch unhandled exception-Web. config

    1 <customErrorsMode= "RemoteOnly"defaultredirect= "Genericerrorpage.htm">2   <ErrorStatusCode= "403"redirect= "Noaccess.htm" />3   <ErrorStatusCode= "404"redirect= "Filenotfound.htm" />4 </customErrors>

    By setting the customerrors node to catch unhandled exceptions, the mode attribute has the following three preset values,

        • Off-Disables custom error messages, both local and remote users will see detailed error messages, the Yellow pages.
        • RemoteOnly-Indicates that the local user will see the detailed error message, and the remote user will see the custom error message. Displays custom (friendly) information only for users who are not running on the local Web server. For security purposes, this setting is recommended so that the details of the application are not displayed to remote clients.
        • On-Indicates that a custom error message (friendly) is visible to both local and remote users.

4. Application-level Catch unhandled exception-Global.asax

    

1     Sub Application_Error (ByValasObjectByVal as EventArgs)2          '  Code that runs if an unhandled error occurs3         Response.Redirect ( " errorinfo.aspx? errmsg=unhandled&detail=" & System.Web.HttpUtility.UrlEncode ( Server.GetLastError.ToString))4     End Sub

. NET provides four error handling mechanisms, which have a certain order of precedence: Page_Error events > ErrorPage properties > Application_Error events > <customErrors> configuration Items.

ASP. NET Unhandled exception

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.