Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Global.asax issue

Global.asax issue

Scheduled Pinned Locked Moved ASP.NET
helpcsharpsysadminquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    markymark82
    wrote on last edited by
    #1

    Hey all, Am trying to use the global.asax file to handle any unhandled exceptions. I want it to do 2 things, log the error to a text file from a class and redirect the user to an error page. I'm sure I've done it before, but can't find my old code. This is what I'm using now:

    void Application_Error(object sender, EventArgs e)
    {
    Exception ex = Server.GetLastError().GetBaseException();
    string errStr = "Message: - " + ex.Message.ToString() + ", Source: - " + ex.Source.ToString();
    ErrorLogger.WriteErrorToFile(errStr);

        Response.Redirect("~/Error.aspx");
    }
    

    The event fires, but when I call my class it ignores that and the redirect and shows the original error on the page. If I take out the class call it does redirect, but I want a log of what happened. (the class writes the error to a text file using a streamwriter). Anyone have an inkling as to why this isn't working? The global files being generated by VS2005 for .net 2.0 if that helps thanks in advance Mark

    E 1 Reply Last reply
    0
    • M markymark82

      Hey all, Am trying to use the global.asax file to handle any unhandled exceptions. I want it to do 2 things, log the error to a text file from a class and redirect the user to an error page. I'm sure I've done it before, but can't find my old code. This is what I'm using now:

      void Application_Error(object sender, EventArgs e)
      {
      Exception ex = Server.GetLastError().GetBaseException();
      string errStr = "Message: - " + ex.Message.ToString() + ", Source: - " + ex.Source.ToString();
      ErrorLogger.WriteErrorToFile(errStr);

          Response.Redirect("~/Error.aspx");
      }
      

      The event fires, but when I call my class it ignores that and the redirect and shows the original error on the page. If I take out the class call it does redirect, but I want a log of what happened. (the class writes the error to a text file using a streamwriter). Anyone have an inkling as to why this isn't working? The global files being generated by VS2005 for .net 2.0 if that helps thanks in advance Mark

      E Offline
      E Offline
      ElSpinos
      wrote on last edited by
      #2

      You could try to clear the error after you handle it in your ErrorLogger, like so:

      void Application\_Error(object sender, EventArgs e) 
      {
          Exception ex = Server.GetLastError().GetBaseException();
          string errStr = "Message: - " + ex.Message.ToString() + ", Source: - " + ex.Source.ToString();
          ErrorLogger.WriteErrorToFile(errStr);
      
          // Clear last exception...
          Server.ClearError();
      
          Response.Redirect("~/Error.aspx");
      }
      

      Fernando Mendes Senior .NET Developer, Architect

      M 1 Reply Last reply
      0
      • E ElSpinos

        You could try to clear the error after you handle it in your ErrorLogger, like so:

        void Application\_Error(object sender, EventArgs e) 
        {
            Exception ex = Server.GetLastError().GetBaseException();
            string errStr = "Message: - " + ex.Message.ToString() + ", Source: - " + ex.Source.ToString();
            ErrorLogger.WriteErrorToFile(errStr);
        
            // Clear last exception...
            Server.ClearError();
        
            Response.Redirect("~/Error.aspx");
        }
        

        Fernando Mendes Senior .NET Developer, Architect

        M Offline
        M Offline
        markymark82
        wrote on last edited by
        #3

        Thanks for the reply, it didn't help, but I did find the cause. My dev environment wasn't debugging properly, it couldn't find the error log file so was skipping the rest of the steps in the Application_Error. Thanks again

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups