2011-07-11 77 views
0

如何測試301錯誤在本地主機中asp.net.I添加Global.asax的頁面,並寫了一碼301錯誤和樣品測試

void Application_BeginRequest(object sender, EventArgs e) 
    { 
     const string www = "http://www.localhost/test"; 
     const string redirect = "http://localhost/test/"; 
     string request = HttpContext.Current.Request.Url.ToString(); 

     if (request.StartsWith(www, StringComparison.InvariantCultureIgnoreCase)) 
     { 
      HttpContext.Current.Response.Status = "301 Moved Permanently"; 
      HttpContext.Current.Response.AddHeader("Location", 
       redirect + request.Substring(www.Length)); 
     } 
    } 

,並配置本地主機通過虛擬目錄,但我不是能看到任何更改作爲我的配置。

回答