Behavior for server.transfer and response.redirect in try-catch-finally block
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");
}
}
}

Nishant VyasPosted Oct 10, 2014, 8:02 AM
For 1st(Response.Redirect): the url points to page3.aspx.
For 2nd(Server.Transfer): the url remains unchanged but all the pages are executed and loaded together in the page. You can expect innumerable errors.
Best way to tackle this is by putting Response.Redirect /Response.End / Server.Transfer in finally block to avoid any confusions.