Asp.net
ASP.NET - 重定向 301
如何在 ASP DOT NET 中永久重定向?我想做一個從我網站上的一個頁面到另一個頁面的 301 重定向。
protected void Page_PreInit(object sender, EventArgs e) { Response.StatusCode = 301; Response.StatusDescription = "Moved Permanently"; Response.RedirectLocation = "AnotherPage.aspx"; HttpContext.Current.ApplicationInstance.CompleteRequest(); }在 4.0 中,有一個簡單的
HttpResponse.RedirectPermanent()方法可以為您完成上述所有操作:Response.RedirectPermanent("AnotherPage.aspx");
ASP.NET 4.0 Beta 1 有一個用於進行 301 重定向的**Response.RedirectPermanent()**方法,例如
Response.RedirectPermanent("AnotherPage.aspx");來自ASP.NET 4.0 和 Visual Studio 2010 Web Development Beta 1 Overview白皮書:
Web 應用程序中的常見做法是隨時間移動頁面和其他內容,這可能導致搜尋引擎中的陳舊連結積累。在 ASP.NET 中,開發人員傳統上通過使用 Response.Redirect 方法將請求轉發到新 URL 來處理對舊 URL 的請求。但是,Redirect 方法會發出一個 HTTP 302 Found(臨時重定向)響應,這會在使用者嘗試訪問舊 URL 時導致額外的 HTTP 往返。
ASP.NET 4.0 添加了一個新的 RedirectPermanent 幫助器方法,可以輕鬆發出 HTTP 301 Moved Permanently 響應。