1

I have a custom error page in an Azure ASP.NET web app where I'd like to display

   <p>Oops - something went wrong.</p>
<p>The most common problem is that you tried to do something that the database enforces shouldn't happen.</p>
<p>The error is:</p>

In web.config I have:

<customErrors mode="On" defaultRedirect="Error.aspx" />

and global.asax:

protected void Application_Error(object sender, EventArgs e)
        {
            Exception objErr = Server.GetLastError().GetBaseException();
            string err = "Error Caught in Application_Error event\n" +
                    "Error in: " + Request.Url.ToString() +
                    "\nError Message:" + objErr.Message.ToString() +
                    "\nStack Trace:" + objErr.StackTrace.ToString();
            EventLog.WriteEntry("Sample_WebApp", err, EventLogEntryType.Error);
        }

Problem: How to display the full exception on the Error.aspx page?

Dave Mateer
  • 6,166
  • 15
  • 69
  • 107

1 Answers1

2

Try adding redirectMode="ResponseRewrite" attribute to the customErrors element if you are using ASP.NET 3.5 SP1. That should preserve the exception information stored in Server.GetLastError(). Then you can add a label to the Error.aspx page and display the exception details, i.e. lblError.Text = Server.GetLastError().ToString().

Here's a similar SO question: ASP.NET custom error page - Server.GetLastError() is null

Community
  • 1
  • 1
Vassili Altynikov
  • 2,049
  • 2
  • 17
  • 24