How to 301 redirect in ASP.NET 4.0?

后端 未结 5 639
再見小時候
再見小時候 2020-12-16 15:59

I am trying to implement URL redirect for the website rather than doing it page by page. I want to do it in the global.asax file. Below is the code i have defined.

I

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-16 16:30

    Building on previous correct and helpful answers, here are a couple specific examples. Assuming you want to delete the old page (as I did), there are a couple of options.

    OPTION 1: Modify the Global.asax

     void Application_BeginRequest(object sender, EventArgs e)
        {
            // Add permanent redirection for retired pages
            if (Request.Url.LocalPath.ToLower().StartsWith("/[OLD PAGE NAME]"))
            {
                Response.RedirectPermanent("/[NEW PAGE NAME]", false);
            }
        }
    

    OPTION 2: Modify the web.config

    
        
            
        
        
    

提交回复
热议问题