asp.net在开发时,在不同的页面间跳转是我们常遇到的一件事,当一个复杂的逻辑在一个页面放不下分成二个或多个页面处理就需要在页面间跳转,用的最多还是用户的登陆吧.
ASP.NET用的最多的跳转是Response.Redirect,这个命令可以直接把请求重定向到一个相对或绝对的路径.它会把当前页面的的Http流阻断直接重定向到新的URL.
而Server.Transfer,这个命令是由IIS服务器直接在服务器端执行跳转,这个跳转的路径必须是相对路径,也就是同一个网站下面的PATH或虚拟目眼录.不能是外网的绝对路径,因为直接是由当前请求页面的同一个HTTP句柄指定请求同一站点上的路径.
它们的区别在哪,先看下HTTP 头吧,先看Response.Redirect
protected void Page_Load(object sender, EventArgs e)
{
Response.Redirect("/redirect.aspx"); //直接重定向到本站的其路径上
}
http://xml.test.com/HttpStatus.aspx -->这个是指我请求执行的页面
GET /HttpStatus.aspx HTTP/1.1
Host: xml.test.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.0.14) Gecko/2009082707 Firefox/3.0.14
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-cn,zh;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: gb2312,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
HTTP/1.x 302 Found -->注意这个302
Cache-Control: private
Content-Type: text/html; charset=utf-8
Location: /redirect.aspx
Server: Microsoft-IIS/7.5
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Sun, 01 Nov 2009 12:12:45 GMT
Content-Length: 133
----------------------------------------------------------
http://xml.test.com/redirect.aspx--> 这个是请求跳转的页面
GET /redirect.aspx HTTP/1.1
Host: xml.test.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.0.14) Gecko/2009082707 Firefox/3.0.14
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-cn,zh;q