Remind me please about custom error handling

G

Guest

I am deep into a project and cannot get this to work correctly.
I am trying to make a custom error page that will be able to know what
exception occurred. I already know about the defaultRedirect page -

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

But how do I reference the exception that occurred from that page?
If I cant, then should I use the Application_Error event in global.asax ?
And if I do that, then what about hiding the error from the user?

Please tell me what I'm missing because I just cant see it now.
 
G

Guest

If you want to capture the exception, you can use Application_Error in
global.asax and use the Server.GetLastError to get the exception.
 
G

Guest

I would still like to redirect the user to another page and log that error.
I guess my question is how can I do both?
 
G

Guest

You can log the error message in Application_Error and then redirect the user
to the error page.
 
G

Guest

Right, but how will that page know the exception that occurred?
global.asax ... error event handler knows the exception from
server.GetLastError but the page wouldn't know the exception. Am I right?
 
G

Guest

Correct. That is why I told you to log your error in Application_Error via
Server.GetLastError and then have the user redirected to the error page that
just displays a typical "We're sorry, .......". If you handle your own error
in Application_Error and you have <customErrors> turned on, ASP.NET will
autotically redirect the user to the error page as long as you don't call
Server.ClearError in Application_Error. If you call Server.ClearError, they
you have to redirect the client to the error page yourself and you can pass
additional parameters to the page such as the actual error messsage.
 

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

Similar Threads

Please help me!!! 3
customErrors 1
Please help me to solve this JS problem 6
Please, help me. 1
Error handling not working 2
custom error 404 1
Frustrations with Error Logging 1
Custom Error Problem 1

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top