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

error trapping question

P: n/a
Tom
On my web app (.net 05) I created a generic error handler class, now I want
to be able to pass the error (from any page) to this class, then redirect the
user to an error page with a user friendly message. I figured out how to
pass the error to the error class, but how can i redirect them to a user
friendly error page afterwards?

Jul 26 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Put the following code in either your page, or in a base page class which
all your pages inherit from.
You would need to replace "ex.aspx" with the name of your error page, and
the Response.Redirect,
you would need to replace the argument with the path to your error page.

Where i have LastException = Server.GetLastError(), you could replace that
with any code you want.

In my base page class LastException is a protected property of type
Exception which simply wraps
a session variable. So i set this, then redirect to my exception page
(ex.aspx) which then takes care of
emailing or logging the exception, and displaying an appropriate message to
the user.

#Region " Page_Error "
Private Sub Page_Error(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Error
LastException = Server.GetLastError

If Me.PageNameFile <"ex.aspx" Then Response.Redirect("~/ex.aspx")
End Sub
#End Region

"Tom" <To*@discussions.microsoft.comwrote
On my web app (.net 05) I created a generic error handler class, now I
want
to be able to pass the error (from any page) to this class, then redirect
the
user to an error page with a user friendly message. I figured out how to
pass the error to the error class, but how can i redirect them to a user
friendly error page afterwards?

Jul 26 '06 #2

P: n/a
Tom
thanks, I actually put the redirect in the web.config file, and I'm passing
the error to my error class and logging it via a log file.

thanks

"Arthur Dent" wrote:
Put the following code in either your page, or in a base page class which
all your pages inherit from.
You would need to replace "ex.aspx" with the name of your error page, and
the Response.Redirect,
you would need to replace the argument with the path to your error page.

Where i have LastException = Server.GetLastError(), you could replace that
with any code you want.

In my base page class LastException is a protected property of type
Exception which simply wraps
a session variable. So i set this, then redirect to my exception page
(ex.aspx) which then takes care of
emailing or logging the exception, and displaying an appropriate message to
the user.

#Region " Page_Error "
Private Sub Page_Error(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Error
LastException = Server.GetLastError

If Me.PageNameFile <"ex.aspx" Then Response.Redirect("~/ex.aspx")
End Sub
#End Region

"Tom" <To*@discussions.microsoft.comwrote
On my web app (.net 05) I created a generic error handler class, now I
want
to be able to pass the error (from any page) to this class, then redirect
the
user to an error page with a user friendly message. I figured out how to
pass the error to the error class, but how can i redirect them to a user
friendly error page afterwards?


Jul 26 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.