customErrors

P

poifull

Hi all,

I specified an aspx page in my web.config/customErrors tag to handle any
error that might occur.
When an exception is thrown, Server.GetLastError() returns null in the error
handling page. Please let me know if my approach is wrong.

Web.config:
<customErrors defaultRedirect="ShowErrorMessage.aspx" mode="On" />


ShowErrorMessage.aspx:

protected void Page_Load(object sender, EventArgs e)
{

Response.Write(Server.GetLastError() == null); // prints True

}


Thanks in advance.
 
G

Guest

Server.GetLastError() gets exception details only in Page_Error and
Application_Error (if the error was not cleared in Page_Error). If you need
the exception details in the custom error's default redirect page, store the
exception in an application variable and access it in the custom error page
(without calling Server.ClearError in Application_Error and Page_Error).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top