Asp.net 将非www重定向到应用程序上的www_BeginRequest-facing循环

Asp.net 将非www重定向到应用程序上的www_BeginRequest-facing循环,asp.net,asp.net-mvc,vb.net,redirect,response,Asp.net,Asp.net Mvc,Vb.net,Redirect,Response,我尝试将非www重定向到www: protected void Application_BeginRequest(Object sender, EventArgs e) { if (!Request.Url.Host.StartsWith("www")) { var path = Request.Url.Scheme+"://www." + Request.Url.Host + Request.Url.PathAndQue

我尝试将非www重定向到www:

protected void Application_BeginRequest(Object sender, EventArgs e)
 {   
   if (!Request.Url.Host.StartsWith("www"))
   {
       var path = Request.Url.Scheme+"://www." + Request.Url.Host + Request.Url.PathAndQuery;
      Response.Clear();
      Response.StatusCode = 301;
      Response.StatusDescription = "Moved Permanently";
      Response.AddHeader("Location", path);
      Response.End();
   }
 }
在请求过程中,它会重定向到:

我建议使用并传递可选参数true来终止请求

Response.RedirectPermanent(path, true);
此方法重载还提供了指定是否 终止或在重定向完成后完成响应 表演

我建议使用并传递可选参数true来终止请求

Response.RedirectPermanent(path, true);
此方法重载还提供了指定是否 终止或在重定向完成后完成响应 表演