开发者

301 error and sample test

开发者 https://www.devze.com 2023-03-19 13:27 出处:网络
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)

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

精彩评论

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

关注公众号