0

I'm trying to handle uncaught exceptions in my Global.asax's Application_Error event. It currently looks like

Sub Application_Error(ByVal sender as object, ByVal e as EventArgs)
    Server.ClearError()
    Response.Redirect("~/ErrorPages/GenericError.aspx")
End Sub

Throwing a brand new exception in the Page_load of another page with

Throw New Exception()

What ends up actually happening is that execution never leaves the source page, and throws the default asp error page citing my exception. Why isn't it being sent to my error page?

EDIT: fixed Response.Redirect. Now looks like:

Response.Redirect("http://mysite/ErrorPages/GenericError.aspx")

Also made the change to my web.config file that was suggested by krshekhar suggested. While I am now being sent to my error page, it is using the default redirection instead of the one I feed it in Application_Error. Any other thoughts?

Community
  • 1
  • 1
Crimius
  • 524
  • 1
  • 8
  • 23

1 Answers1

1

The solution should be customErrors mode="On"
The only problem looks for your qustion is web.config entry for customError it should be as follows

 <configuration>
    <system.web>
       <customErrors mode="On" defaultRedirect="GenericErrorPage.htm">
           <error statusCode="403" redirect="NoAccess.htm" />
           <error statusCode="404" redirect="FileNotFound.htm" />
            ...
       </customErrors>
    </system.web>
  </configuration>

Helpful links
ASP.NET custom error page - Server.GetLastError() is null
CustomErrors mode="Off"

Community
  • 1
  • 1
शेखर
  • 16,910
  • 12
  • 52
  • 105
  • Changed the `web.config` as suggested. I get to the error page now, but it is using the default redirection from `` and not the redirection I feed it in `Application_Error`. – Crimius Feb 08 '13 at 19:54
  • @Crimius remove the `defaultRedirect` and use `Response.Redirect("pagename",false)` – शेखर Feb 09 '13 at 04:01
  • The page now errors due to there being no default redirect in the `` tag. – Crimius Feb 11 '13 at 13:34