Arj*_*jun 16 asp.net iis redirect
如何在ASP DOT NET中永久重定向?我想从我的网站上的一个页面到另一个页面进行301重定向.
Chr*_*tow 37
protected void Page_PreInit(object sender, EventArgs e)
{
Response.StatusCode = 301;
Response.StatusDescription = "Moved Permanently";
Response.RedirectLocation = "AnotherPage.aspx";
HttpContext.Current.ApplicationInstance.CompleteRequest();
}
Run Code Online (Sandbox Code Playgroud)
在4.0中,有一个简单的HttpResponse.RedirectPermanent()方法可以为您完成上述所有操作:
Response.RedirectPermanent("AnotherPage.aspx");
Run Code Online (Sandbox Code Playgroud)
Chr*_*tow 15
ASP.NET 4.0 Beta 1有一个用于执行301重定向的Response.RedirectPermanent()方法,例如
Response.RedirectPermanent("AnotherPage.aspx");
Run Code Online (Sandbox Code Playgroud)
从ASP.NET 4.0和Visual Studio 2010 Web开发Beta 1概述白皮书:
Web应用程序中的常见做法是随着时间的推移移动页面和其他内容,这可能导致搜索引擎中过时链接的累积.在ASP.NET中,开发人员通常使用Response.Redirect方法将请求转发到新URL,从而处理对旧URL的请求.但是,Redirect方法会发出HTTP 302 Found(临时重定向)响应,当用户尝试访问旧URL时会导致额外的HTTP往返.
ASP.NET 4.0添加了一个新的RedirectPermanent辅助方法,可以轻松发出HTTP 301 Moved Permanently响应.