By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,115 Members | 898 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,115 IT Pros & Developers. It's quick & easy.

Remind me please about custom error handling

P: n/a
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.
Nov 19 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
If you want to capture the exception, you can use Application_Error in
global.asax and use the Server.GetLastError to get the exception.

"vbMental" wrote:
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.

Nov 19 '05 #2

P: n/a
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?

"Tu-Thach" wrote:
If you want to capture the exception, you can use Application_Error in
global.asax and use the Server.GetLastError to get the exception.

"vbMental" wrote:
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.

Nov 19 '05 #3

P: n/a
You can log the error message in Application_Error and then redirect the user
to the error page.

"vbMental" wrote:
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?

"Tu-Thach" wrote:
If you want to capture the exception, you can use Application_Error in
global.asax and use the Server.GetLastError to get the exception.

"vbMental" wrote:
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.

Nov 19 '05 #4

P: n/a
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?

"Tu-Thach" wrote:
You can log the error message in Application_Error and then redirect the user
to the error page.

"vbMental" wrote:
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?

"Tu-Thach" wrote:
If you want to capture the exception, you can use Application_Error in
global.asax and use the Server.GetLastError to get the exception.

"vbMental" wrote:

> 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.

Nov 19 '05 #5

P: n/a
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.

"vbMental" wrote:
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?

"Tu-Thach" wrote:
You can log the error message in Application_Error and then redirect the user
to the error page.

"vbMental" wrote:
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?

"Tu-Thach" wrote:

> If you want to capture the exception, you can use Application_Error in
> global.asax and use the Server.GetLastError to get the exception.
>
> "vbMental" wrote:
>
> > 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.

Nov 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.