locked
Trouble with customErrors mode RRS feed

  • Question

  • User675515096 posted

    I'm trying to push all unhandled errors to my errors.aspx page but it doesn't seem to be working. I have the following set in my Global.asax file and web.config:

    Global.asax:

    void Application_Error(object sender, EventArgs e)
            {
                // Code that runs when an unhandled error occurs
                // Get the exception object.
                Exception exc = Server.GetLastError();
    
                Response.BufferOutput = true;
                Response.Redirect("~/error.aspx");
                adminEmailError.SendMailMessage(exc.ToString());
    
                Server.ClearError();
            }

    web.config:

    	<system.web>
    		<customErrors mode="Off" />
    	</system.web>
    




    Wednesday, November 20, 2013 12:00 PM

Answers

  • User71929859 posted

    I'm trying to push all unhandled errors to my errors.aspx page but it doesn't seem to be working.

    Then why don't you simply have below in your web.config file. customErrors tag is there exactly for that reason.

    <system.web>
       <customErrors defaultRedirect="error.aspx" mode="On">
    </system.web>

    As for 404, you would have to configure the error page for 404 error code in IIS since it's a HTTP error (not something which throws from your code)

    http://technet.microsoft.com/en-us/library/cc753103(v=ws.10).aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 22, 2013 11:01 PM

All replies

  • User-484054684 posted

    Hi Brandozz,

    Could you please elaborate on the error details, as it would be difficult to understand the exact error when you say it doesn't seem to be working?

    However, setting cutomErrors to off and writing the code in Application Error looks to be fine.

    Reference: http://msdn.microsoft.com/en-us/library/24395wz3(v=vs.100).aspx
     
    A few pointers:

    1. If it is not redirecting to the proper page, please cross check if the path of the error.aspx page is correct.
       i.e,, Response.Redirect("~/error.aspx");   
    Is ~  character necessary based on your path of the error.aspx? or can this be accessed with out ~ etc?          

    2. adminEmailError.SendMailMessage(exc.ToString());
    Is there any error on this line? To find out the exact error, either you would need to debug or put this in try/catch to know the exact error in this line.

    3. Response.BufferOutput = true;
    Also not sure if this might have caused any other issues.

    Wednesday, November 20, 2013 12:23 PM
  • User675515096 posted

    Should this catch a 404 error. I'm trying to test it using two different scenerios:

    1. Compilier error: I just removed a tag from my page, saved and tried to access.

    2. Navigating to a page that does not exist. 

    I'm not receiving any errors, when I try to navigate to a page that does not exist I just get your typical Server Error with not redirect to the error page, when I receive a Compilier error it displays the stack trace in the browser window. 

    Wednesday, November 20, 2013 12:32 PM
  • User-1225287840 posted

    Try clearing the error from the server.

    ' Clear the error from the server
      Server.ClearError()

    Have a look at this link,
    http://msdn.microsoft.com/en-us/library/24395wz3%28v=vs.100%29.aspx
    Wednesday, November 20, 2013 1:11 PM
  • User675515096 posted

    I already have that in my code. 

    Wednesday, November 20, 2013 1:18 PM
  • User675515096 posted

    I do have one error in my Global.asax.cs file. I'm receiving the message: "The name 'AuthConfig' does not exist in the current context".

    I commented out that line but I'm still not haveing any luck redircting errors to errors.aspx.

    Wednesday, November 20, 2013 1:22 PM
  • User71929859 posted

    I'm trying to push all unhandled errors to my errors.aspx page but it doesn't seem to be working.

    Then why don't you simply have below in your web.config file. customErrors tag is there exactly for that reason.

    <system.web>
       <customErrors defaultRedirect="error.aspx" mode="On">
    </system.web>

    As for 404, you would have to configure the error page for 404 error code in IIS since it's a HTTP error (not something which throws from your code)

    http://technet.microsoft.com/en-us/library/cc753103(v=ws.10).aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 22, 2013 11:01 PM