ErrorPage from ErrHandler

E

Eje

I'm designing a 3-tier web application in .NET. In the
middle tier I have an error handler. I use Try-Catch
where I feel it's necessary. If I get a critical error I
would like to redirect to a "Critical Error page"
directly from the error handler without going up to the
UI tier. Is that possible and in that case how does the
code look?

Eje
 
G

Guest

Hi Eje,

Another alternative is to inherit your page from a custom defined class that
inherits from System.Web.UI.Page. In that class, you must hook to the
Page_Error event.

That class (a regular c# class) should be something like :

public class MyBasePage: System.Web.UI.Page
{
public BasePage()
{
this.Error += new System.EventHandler(this.Page_Error);
}

protected void Page_Error(Object source, EventArgs e)
{
// put your code here
// to get access to the last exception use Server.GetLastError()
}
}

Then, you must replace in your page this

public class yourPageName: System.Web.UI.Page

with

public class yourPageName: MyBasePage


In the base page you can also perform any operation that is common to all of
your pages (or at least the ones that inherit from it).

You can get more info about this technique her
http://msdn.microsoft.com/library/d...y/en-us/dnpatterns/html/ImpPageController.asp

Another possibility is to use HttpModules and HttpHandlers. You can find a
great example of this technique here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/elmah.asp

Regards,
Leon
 

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,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top