error trapping question

G

Guest

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?
 
A

Arthur Dent

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
 
G

Guest

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
 

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

Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,252
Latest member
MeredithPl

Latest Threads

Top