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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Custom error page is ignored

Custom error page is ignored

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netsysadminhelp
3 Posts 2 Posters 1 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.
  • A Offline
    A Offline
    ake_krakbar
    wrote on last edited by
    #1

    Hello folks! I´ve implemented some custom error handling that writes the error to a log file then redirects the user to my custom error page. The strange thing is: this all works fine when i run the project in VS2005 using f5 but when i just choose to directly go to any page causing an error (like 'view in browser') error logging still works ok but my custom error page is ignored. Instead the regular asp.net error page is used. It´s done like this... First the web.config: My httpModule: public class ErrorHandlingModule : IHttpModule { private HttpApplication application; void IHttpModule.Init(HttpApplication app) { this.application = app; this.application.Error += new EventHandler(ErrorHandler); } private void ErrorHandler(Object sender, EventArgs e) { Exception ex = application.Server.GetLastError(); string errorString = "\n\n" + DateTime.Now.ToString() + " " + ex.Message + "\nInnerException: " + ex.InnerException; TextWriter tw = File.AppendText(application.Server.MapPath("errorLog.txt")); tw.WriteLine(errorString); tw.Close(); application.Server.Execute("Error.aspx"); application.Server.ClearError(); } #region IHttpModule Members public void Dispose() { } #endregion } And, finally the error page: protected void Page_Load(object sender, EventArgs e) { Exception ex = Server.GetLastError(); if (ex != null) lblErrorMessage.Text = ex.Message + "

    " + ex.InnerException; } Hope it makes sense. /J

    T 1 Reply Last reply
    0
    • A ake_krakbar

      Hello folks! I´ve implemented some custom error handling that writes the error to a log file then redirects the user to my custom error page. The strange thing is: this all works fine when i run the project in VS2005 using f5 but when i just choose to directly go to any page causing an error (like 'view in browser') error logging still works ok but my custom error page is ignored. Instead the regular asp.net error page is used. It´s done like this... First the web.config: My httpModule: public class ErrorHandlingModule : IHttpModule { private HttpApplication application; void IHttpModule.Init(HttpApplication app) { this.application = app; this.application.Error += new EventHandler(ErrorHandler); } private void ErrorHandler(Object sender, EventArgs e) { Exception ex = application.Server.GetLastError(); string errorString = "\n\n" + DateTime.Now.ToString() + " " + ex.Message + "\nInnerException: " + ex.InnerException; TextWriter tw = File.AppendText(application.Server.MapPath("errorLog.txt")); tw.WriteLine(errorString); tw.Close(); application.Server.Execute("Error.aspx"); application.Server.ClearError(); } #region IHttpModule Members public void Dispose() { } #endregion } And, finally the error page: protected void Page_Load(object sender, EventArgs e) { Exception ex = Server.GetLastError(); if (ex != null) lblErrorMessage.Text = ex.Message + "

      " + ex.InnerException; } Hope it makes sense. /J

      T Offline
      T Offline
      ToddHileHoffer
      wrote on last edited by
      #2

      can you use the web.HttpResponse.Redirect method. replace application.Server.Execute("Error.aspx"); application.Server.ClearError(); with HttpContext.Current.Response.Redirect("Error.aspx");

      how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things --thedailywtf 3/21/06

      A 1 Reply Last reply
      0
      • T ToddHileHoffer

        can you use the web.HttpResponse.Redirect method. replace application.Server.Execute("Error.aspx"); application.Server.ClearError(); with HttpContext.Current.Response.Redirect("Error.aspx");

        how vital enterprise application are for proactive organizations leveraging collective synergy to think outside the box and formulate their key objectives into a win-win game plan with a quality-driven approach that focuses on empowering key players to drive-up their core competencies and increase expectations with an all-around initiative to drive up the bottom-line. But of course, that's all a "high level" overview of things --thedailywtf 3/21/06

        A Offline
        A Offline
        ake_krakbar
        wrote on last edited by
        #3

        Unfortunately that doesn´t work. Using application.Server.Execute("Error.aspx") makes the aspnet process run error.aspx in the current page´s context, wich means that the exception is still available.

        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