Will a 301 be sent through a server.transfer?
PageA.aspx:
protected void Page_Load(object sender, EventArgs e)
{
Response.Status = "301 Moved Permanently";
Server.Transfer("/pageB.aspx");
}
Will a 301 be sent through a server.transfer?
PageA.aspx:
protected void Page_Load(object sender, EventArgs e)
{
Response.Status = "301 Moved Permanently";
Server.Transfer("/pageB.aspx");
}
If you do need to redirect after a Server.Transfer
, you could do it manually:
this.Response.Status = "301 Moved Permanently";
this.Response.RedirectLocation = "Default2.aspx";
Details:
Server.Transfer
does not cause redirect
See the MSDN:
Server.Transfer acts as an efficient replacement for the Response.Redirect method. Response.Redirect specifies to the browser to request a different page. Because a redirect forces a new page request, the browser makes two requests to the Web server, so the Web server handles an extra request. IIS 5.0 introduced a new function, Server.Transfer, which transfers execution to a different ASP page on the server. This avoids the extra request, resulting in better overall system performance, as well as a better user experience.
And actually I just tried your code and it doesn't work.
It did sent the 301 status:
HTTP/1.1 301 Moved Permanently
Server: ASP.NET Development Server/10.0.0.0
Date: Thu, 14 Jun 2012 18:54:22 GMT
X-AspNet-Version: 4.0.30319
Cache-Control: private
Content-Type: text/html; charset=utf-8
Content-Length: 626
Connection: Close
That's the repsonse from Fiddler.
But it is not working
I think the reason why it doesn't work, is because when you send a 3xx status from the server you need to send back the URL used to redirect (which causes a second request to the server). This is done automatically when you use Response.Redirect
, but Server.Transfer
does not so you are sending a redirect status from the server without the URL that's why it is not working