Capturing ASP. Application Startup Exceptions

Source: Internet
Author: User

It has become common practice to perform tasks during an ASP. Applications start up process. These tasks may include registering routes, configuring filters, wiring up third party dependencies, and so much more. Here is the default ASP. NET MVC Application startup code pulled from the sample.

protected void Application_Start () {    arearegistration.registerallareas ();    Filterconfig.registerglobalfilters (globalfilters.filters);    Routeconfig.registerroutes (routetable.routes);    Bundleconfig.registerbundles (bundletable.bundles);}

These tasks is crucial to the function of the application, but they don't always execute cleanly. Exceptions in the startup process can mean the application never got a change-to-wire up exception handlers. This can make it difficult-to-debug issues in production, causing us to turn customErrors off.

<customerrors mode="Off" />

To insure your capture application startup exceptions, remember to implement Application_Error .

Private voidApplication_Error (Objectsender, EventArgs e) {   //a static Boolean at the application level   if(failedtostartup) {//Step 1:write to a dependable logging storage//option 1:trace//option 2:raygun//option 3:filesystem//Step 2:redirect to Non-app based Error page//obviously needs to exist outside your app//since it failed to startup  }}

Now we should get a log message This lets us know what the exception are, and additionally our users get to see an error PA GE that isn ' t of the red and yellow variety. Note, it may be the default error logging mechanism that we've chosen that's causing our application failure. I recommend having a fallback logging mechanism if possible; Is Trace a safe bet.

Khalid abuhakmeh– software Developer and all Around nice guy

Original link: http://www.khalidabuhakmeh.com/capturing-asp-net-application-startup-exceptions

Capturing ASP. Application Startup Exceptions

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.