Response Permanent Redirect in MVC not issuing 301 or changing URL

前端 未结 1 1285
情话喂你
情话喂你 2021-01-15 22:02

I am converting an old ASP.NET web forms site to ASP.NET MVC 5. I would like to issue permanent redirects for the old page URLs.

Here is what I have done -

相关标签:
1条回答
  • 2021-01-15 22:16

    Here is my solution (Global.asax)

    protected void Application_PreRequestHandlerExecute(Object sender, EventArgs e)
            {
                string currentUrl = HttpContext.Current.Request.Path.ToLower();
                if (currentUrl.EndsWith("/about/about.aspx"))
                {
                    Response.Status = "301 Moved Permanently";
                    Response.AddHeader("Location", "/About");
                    Response.End();
                }
            }
    

    From answer here: Global 301 redirection from domain to www.domain

    0 讨论(0)
提交回复
热议问题