开发者

301 error and sample test

how to test 301 error in local host in asp.net.I add global.asax page and written a code

 void Application_BeginRequest(object sender, EventArgs e)
     {
         const string www = "http://开发者_Go百科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));
         }
     }

and configure localhost through virtual directory but i m not able to see any change as my configure.


Why don't you use HttpResponse.RedirectPermanent() instead? It's built in:

HttpContext.Current.Response.RedirectPermanent(redirectUrl); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜