1
Reply

server.transfer and response.redirect in try-catch-finally

Anil Kumar Murmu

Anil Kumar Murmu

Jun 25 2014 12:59 AM
2k

Behavior for server.transfer and response.redirect in try-catch-finally block

Hello every one,
I came across a code in try-catch-finally block where i found more clarification would be needed.  Could any one please explain why exception arises in following codes? How to handle such exceptions?
 
Thanks in advance for any possible answers. 
 
Regards
Anil Kumar 
 

Code-1:

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

namespace Web_Test

{

public partial class WebForm : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

try

{

Response.Redirect("Page1.aspx");

}

catch

{

Response.Redirect("Page2.aspx");

}

finally

{

Response.Redirect("Page3.aspx");

}

}

}

Code-2

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

namespace Web_Test

{

public partial class WebForm : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

try

{

Server.Transfer("Page1.aspx");

}

catch

{

Server.Transfer("Page2.aspx");

}

finally

{

Server.Transfer("Page3.aspx");

}

}

}


Answers (1)