1. Server.Transfer 服务器端跳转web
webform1.aspx跳转到webform2.aspx页面浏览器
webform1.aspx代码以下:服务器
protected void Page_Load(object sender, EventArgs e) { this.Server.Transfer("WebForm2.aspx"); this.Response.Write("webform1"); }
当代码执行到Server.Transfer语句会马上跳转到WebForm2.aspx页面执行,而不会再执行后续的语句this.Response.Write("webform1"); 缘由是Server.Transfer语句会抛出异常,若是试着抓住这个异常,会发现是ThreadAbortException, 由Transfer函数内部调用Thread.Abort引起,因此后续的代码不会执行。以下图所示:函数
2. Response.Redirect 客户端浏览器跳转this
Response.Redirect的后续的语句也不会执行, 一样会抛出ThreadAbortException, 以下图所示:url
另外Response.Redirect属于客户端跳转,请求直接返回,返回码是302。客户端浏览器收到302和须要跳转的url location,发出第二个请求到这个url。spa