Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I see a few problems:</p> <ul> <li><p>You will probably want to handle HttpUnhandledException in your error handler. This is what most of the exceptions raised by your page will be.</p></li> <li><p>I don't see the value of a handle and resume (PostHandlingAction = None) policy where you call Server.ClearError(). Basically your page has thrown an exception and you are doing nothing. Best case scenario, the user sees an empty page. Worst case, you could have a partially rendered page with no indication what happened.</p></li> <li><p>I also don't see the point of potentially throwing an exception from your error handler. You're either going to end up with the yellow screen of death or your going to force another error page to be called (e.g. a customErrors redirect defined in web.config).</p></li> <li><p><del>Your HandleException logic does not account for the NotifyRethrow scenario.</del> <em>(Removed based on comment that there is a customError redirect)</em>.</p></li> </ul> <p>Using <a href="https://stackoverflow.com/questions/1751052/using-enterprise-library-exception-handling-application-block-in-asp-net-code-r#1751971">@vladhorby's ErrorPage</a> and keeping your main logic would give something like this:</p> <pre><code>protected void Application_Error() { Exception error = Server.GetLastError(); if (error is HttpUnhandledException) { error = error.InnerException; } Exception errorToThrow; if (ExceptionPolicy.HandleException(error, "Application Error", out errorToThrow)) { Response.Redirect(string.Format("ErrorPage.aspx?Message={0}", Uri.EscapeDataString((errorToThrow ?? error).Message))); } else { Server.ClearError(); } } </code></pre> <p><br> A few notes about the above code:</p> <ul> <li><p>If ErrorPage.aspx throws an Exception for some reason you could end up in an infinite loop so make sure that ErrorPage.aspx has it's own Page_Error to try to avoid unhandled exceptions propagating to the global error handler.</p></li> <li><p>It does not take into account objections 2 and 3. :)</p></li> </ul> <p>I'm not sure about your situation and requirements but have you considered using <a href="http://dotnetslackers.com/articles/aspnet/ErrorLoggingModulesAndHandlers.aspx" rel="nofollow noreferrer">ELMAH</a>?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload