ASP.NET - [removed]

后端 未结 3 1893
温柔的废话
温柔的废话 2021-02-07 10:06

How do I redirect permanently in ASP DOT NET? I\'d like to do a 301 redirect from one page on my site to another page.

3条回答
  •  终归单人心
    2021-02-07 10:27

    protected void Page_PreInit(object sender, EventArgs e)
    {
        Response.StatusCode = 301;
        Response.StatusDescription = "Moved Permanently";
        Response.RedirectLocation = "AnotherPage.aspx";
        HttpContext.Current.ApplicationInstance.CompleteRequest();
    }
    

    And in 4.0, there's a simple HttpResponse.RedirectPermanent() method that does everything above for you:

    Response.RedirectPermanent("AnotherPage.aspx");
    

提交回复
热议问题