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);
精彩评论