Server.Transfer in Application_Error()

  • Thread starter Thread starter Kris Meher
  • Start date Start date
K

Kris Meher

Hi
My code
Global.asax

Application_Start()
{
// Code
// There is possibility of Exception in above Code
}

Applicaton_Error()
{
// in the Redirect Page i m displying the Error Message
//from Server.GetLastError();
Server.Transfer("CapError.aspx");
}

My problem:-
For the "First" time when the application is loaded,
there is possible exception.
After encountring Exception the Asp.net is executing
Application_Erorr().
But the page is "not" Transfering to CapError.aspx.
(I tried with Response.Redirect as well)
I didnt touch WebConfig file.



Could some one please help me out.

Thanks
Kris
 
By the time Application_Error runs, the page has already finished
processing, so there is no context in which to transfer the user.

You should handle Page_Error on your page. If all your pages transfer to
the same page in case of error, I would recommend having a base class that
all your pages inherit from that handles this event.
 
Thanks a lot..
All my Pages are inherited from a base class.
I tired the below code in base class.

public BasePage()
{

// Page.Init += new
System.EventHandler(this.Page_Error);
}
// public void Page_Error(Object sender,
EventArgs e)
// {
// // Implementation here
// Server.Transfer("caperror.aspx");
// }

Basically for the first time when it is loading the app
it is encountring the exception(it is not executing the
complete appliction_start() function).
After that it goes to Application_Error(), there it
doesnt know any thing about the context of Application...

Still it is not working after adding the event page_error
to base class.
Is there any way i can achieve this :(
Thanks
Kris
 
the correct syntax is:

public BasePage : System.Web.UI.Page
{
protected override void OnInit(EventArgs e)
{
this.Error += new System.Eventhandler(this.Page_Error);
}

public void Page_Error(Object sender, EventArgs e)
{
// do generic error handling here
}
}
 
Back
Top