服务器。转移和响应。重定向
Server和Response都是ASP.NET中的对象。Server对象为与服务器相关的各种任务提供方法和属性。Transfer是Server对象的一个方法,它将当前状态的信息发送到另一个.asp文件进行处理。响应对象描述与服务器响应相关的方法和属性。Redirect是Response对象的一个方法,它向浏览器发送一条消息,使浏览器连接到不同的URL。尽管服务器。转移和响应。重定向can be used to transfer a user from one page to another, they are different in how they actually perform this task.
Response.Redirect是什么?
Redirect是Response对象中的一个方法。当Response方法被调用时,它将向用户的浏览器发送HTTP代码302和所请求网页的URL。HTTP代码302通知用户的浏览器所请求的资源位于不同的URL下。当浏览器接收到代码时,它在新位置打开资源。被请求的网页可以驻留在与包含请求的页面相同的服务器上,也可以驻留在其他服务器上。当请求与当前页面位于同一服务器上的网页时,Response方法可以使用如下:
Response.Redirect(“nextPage.html”);
当请求驻留在另一台服务器上的网页时,Response方法可以使用如下:
Response.Redirect(“http://www.newServer.com/newPage.aspx”);
Server.Transfer是什么?
如前所述,Transfer是服务器对象的一个方法。当调用Transfer方法时,原始请求将被修改为传输到同一服务器中的其他页面。当使用服务器请求新页面时。转移,URL shown in the users’ web browser does not change. This is because the transfer happens in the server side and the browser does not have any knowledge about the transfer. By using the second overload for Server.Transfer(string path, bool preserveForm) and setting the second parameter as true, posted form variables and query strings can be made available to the second page.
服务器之间有什么区别。转让和Response.Redirect吗?
尽管服务器。转移和响应。重定向can be used to transfer a user from one page to another, there are some differences between the two methods. Besides the apparent syntactical difference, Response.Redirect makes a roundtrip to the server, while Server.Transfer changes the focus of the web server to a different web page. Therefore, by using Server.Transfer, server resources can be preserved. On the other hand Response.Redirect could be used to redirect the user to a web page in another server whereas Server.Transfer can only be used to redirect the user to web pages on the same server. Also by using Server.Transfer, properties of the previous page can be accessed by the new page but this is not possible with Response.Redirect. Additionally, Response.Redirect changes the URL in the address bar of the browser when the new page is accessed but when using the Server.Transfer the original URL is retained and the content of the page is just replaced. So the user cannot use it to bookmark the new page.
留下一个回复