Question

I hear that we can use defaultRedirect clause of the <customErrors> section to specify a custom errors page (or more than one, each one handling a specific HTTP error). I added an error page to my project and set it like so in web.config. Now when an HTTP error occurs, ASP.NET takes me to the designated error page, but I'm not sure exactly what happened that took us here.

Is there a way for us to tell ASP.NET to spit out error code or description in our page? Adding one page for each HTTP error seems to be a lot of work. I'm looking for some server-side variable/macro or something I could embed in that page's body.

Was it helpful?

Solution

Try using the Server.GetLastError() method.

From MSDN link:

The GetLastError method returns an ASPError Object describing the error condition that occurred. This method is available only before the .asp file has sent any content to the client.

This article on CodeProject has a pretty good tutorial on error handling in ASP.net.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top