Server.Transfer VS Response.Redirect – Simplified
https://www.codeproject.com/Articles/775221/Server-Transfer-VS-Response-Redirect-Simplified
Introduction
In ASP.NET, some of the concepts do the same task but are meant to be used in different scenarios. One such concept which is confusing and most discussed among developers is the difference between “Server.Transfer” and “Response.Redirect”.

“response.redirect” and “server.transfer” helps to transfer user from one page to other page while the page is executing. But the way they do this transfer / redirect is very different.
In this short blog, we will discuss how they differ and in which scenarios we should use them.
In case you are a visual person and would like see a demonstration rather than theory, I would suggest to see the below Facebook video which explains the difference in a more demonstrative way.
“Server.Transfer”vs “response.Redirect”
The main difference between them is who does the transfer. In “response.redirect”, the transfer is done by the browser while in “server.transfer”, it’s done by the server. Let us try to understand this statement in a more detailed manner.
In “Server.Transfer”, following is the sequence of how the transfer happens:
- User sends a request to an ASP.NET page. In the below figure, the request is sent to “
WebForm1” and we would like to navigate to “Webform2”. - Server starts executing “
Webform1” and the life cycle of the page starts. But before the complete life cycle of the page is completed, “Server.transfer” happens to “WebForm2”. - “
Webform2” page object is created, full page life cycle is executed and output HTML response is then sent to the browser.

One important point to note here is the URL is not changed to the target page. If you have sent request from “Webform1.aspx” to redirect to “WebForm2.aspx” on the browser URL, you will still see “WebForm1.aspx”.
While in “Response.Redirect”, following is the sequence of events for navigation:
- Client (browser) sends a request to a page. In the below figure, the request is sent to “
WebForm1” and we would like to navigate to “Webform2”. - Life cycle of “
Webform1” starts executing. But in between the life cycle “Response.Redirect” happens. - Now rather than server doing a redirect, he sends a HTTP 302 command to the browser. This command tells the browser that he has to initiate a
GETrequest to “Webform2.aspx” page. - Browser interprets the 302 command and sends a
GETrequest for “Webform2.aspx”.

In this case, you will see the URLs are changed as per redirection. So if you have redirected to “Webform2.aspx”, then on the browser URL, you should see “WebForm2.aspx”.
In other words, “Server.Transfer” is executed by the server while “Response.Redirect” is executed by the browser. “Response.Redirect” needs two requests to do a redirect of the page.
So When to Use “Server.Transfer” and When to Use “Response.Redirect”?
Use “Server.Transfer” when you want to navigate pages which reside on the same server, use “Response.Redirect” when you want to navigate between pages which resides on different server and domain.

Below goes the consolidated table with all the differences as discussed at the top.
| Server.Transfer | Response.Redirect | |
| Redirection | Redirection is done by the server. | Redirection is done by the browser client. |
| Browser URL | Does not change. | Changes to the redirected target page. |
| When to use | Redirect between pages of the same server. | Redirect between pages on different server and domain. |
What is the Importance of “preserveForm” Flag in “Server.Transfer”?
“Server.Transfer” helps to redirect from one page to other page. If you wish to pass query string and form data of the first page to the target page during this redirection, you need to set “preserveForm” to “true” as shown in the below code.
Server.Transfer("Webform2.aspx",true);
By default, the value of “preserveForm” is “true”.
Response.Redirect(URL,true) vsResponse.Redirect(URL,false) ?
Response.Redirect(URL,false): Client is redirected to a new page and the current page on the server will keep processing ahead.
Response.Redirect(URL,true): Client is redirected to a new page but the processing of the current page is aborted.

Below is a Facebook video which demonstrates practically the difference between server.transfervsresponse.redirect. A big thanks to www.questpond.com to allow me to publish this videos for free on Facebook.
Server.Transfer VS Response.Redirect – Simplified的更多相关文章
- 1. Server.Transfer和Response.Redirect
今天在使用ServerTransfer和Response.Redirect定位到当前页面来实现刷新页面时,发现了一些现象: 1.使用Response.Redirect刷新本页面,造成当前页面显示的数据 ...
- Server.Transfer 和 Response.Redirect 用法区别
在ASP.NET中,在后台传值方式目前大多都是用 Response.Redirect("页面地址") 来重定向页面的,但是现在还有一种方式也可以达到重定向页面的作用,而且在某些时刻 ...
- Server Transfer()和Response.Redirect()的使用
一.Server Transfer() Server.Transfer:对于当前请求,终止当前页的执行,并使用指定的页url路径来开始执行一个新页. 1. Server.Transfer只能够转跳到本 ...
- Server.Transfer和Response.Redirect区别
根本上,Response是叫浏览器去重新转向到指定的网页,而Server自然是发生在服务器端为主了,因此会有以下区别:1. Server.Transfer只能够转跳到本地虚拟目录指定的页面,而Resp ...
- 页面跳转 Server.Transfer和 Response.Redirect的区别
1.Server.Transfer 用于把处理的控制权从一个页面转移到另一个页面,在转移的工程中没有离开服务器内部控件(如request,session等)保存的信息不变.因此你能从a页面跳转到b页面 ...
- Server.Transfer和Response.Redirect的区别
(1)Server.Transfer方法: Server.Transfer("m2.aspx");//页面转向(服务器上执行). 服务器停止解析本页,保存此页转向前的数据后,再使页 ...
- asp.net知识汇总-页面跳转Server.Transfer和Response.Redirect
1. Server.Transfer 服务器端跳转 webform1.aspx跳转到webform2.aspx页面 webform1.aspx代码如下: protected void Page_Loa ...
- c#页面重定向,Server.Transfer 和 Response.Redirect
Server.Transfer() 重定向发生在服务器端,把处理的控制权从当前页面转移到另一个页面,在转移的工程中没有离开服务器内部控件(如request,session等)保存的信息不变. 1.只能 ...
- ASP.NET页面传值之Server.Transfer 和Response.Direct
先看实例: B.apsx: public string TextBox1Text { get { ...
随机推荐
- linux 的基本操作(linux系统的日常管理)
系统的日常管理 笔者在前面介绍的内容都为linux系统基础类的,如果你现在把前面的内容全部很好的掌握了,那最好了.不过笔者要说的是,即使你完全掌握了,你现在还是不能作为一名合格的linux系统管理员的 ...
- 文文---Set,Map
Set和Map Set:类似数组 成员的值是唯一的 下有 add(),has(),delete(),clear(),size 等方法 Map:类似于对象 成员的值是唯一的 下有 set(),has() ...
- Java应用之POI
POI的简介 Apache POI是Apache软件基金会的开放源码函式库,POI提供API给Java程序对Microsoft Office格式档案读和写的功能. HSSF的概况 HSSF 是Horr ...
- VM装mac10.9教程+报错信息解决办法
VM装mac10.9教程+报错信息解决办法 教程1: 教你在Vmware 10下安装苹果Mac10.9系统 地址:http://tieba.baidu.com/p/2847457021 教程2: VM ...
- Golang数据类型总结及其转换
golang数据类型 基本类型:boolean,numeric,string类型的命名实例是预先声明的. 复合类型:array,struct,指针,function,interface,slice,m ...
- python-----函数参数类型
#函数参数类型:1 位置参数 2 默认参数 3 关键字参数 4可变参数 包裹位置参数*args 包裹关键字参数 **kargs#参数位置顺序:先位置参数,默认参数,包裹位置,包裹关键字(定义和调用都应 ...
- Redis入门到高可用(十五)—— GEO
一.简介 二.应用场景 三.API 1.geoadd 2.geopos 3.geodist 4.georadius 四.相关说明
- java框架之Spring(5)-注解驱动开发
准备 1.使用 maven 创建一个 java 项目,依赖如下: <dependency> <groupId>org.springframework</groupId&g ...
- 第十二届GOPS全球运维大会2019深圳站即将开幕
第十二届 GOPS 全球运维大会深圳站 会议召开时间:2019年4月12日-13日 会议召开地点:深圳圣淘沙酒店(翡翠店) 会议主办单位:高效运维社区 票务合作伙伴:活动家 会议报名地址:https: ...
- Oracle 25用户的权限管理
理解什么是权限 权限指的是执行特定命令或访问数据库对象的权利. 理解权限的作用 (保证)数据库安全性:系统安全性,数据安全性 了解权限的分类 系统权限: 允许用户执行特定的数据库操作,如创建表.创建索 ...