ASP.NET - 重定向301

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)

  • 在我的帮助器类中,我创建了一个允许我输入的扩展方法:Response.PermananentRedirect("someUrl.aspx"); - 方法调用是:public static void PermanentRedirect(此System.Web.HttpResponse响应,字符串uri) (4认同)
  • 尼斯.可以设置Response.RedirectLocation而不是调用Response.AddHeader. (4认同)

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响应.

  • +1随着.Net 4推出,这变得更加正确. (2认同)