日期:2014-05-17 浏览次数:20579 次
protected void Application_BeginRequest(object sender, EventArgs e)
{
string authority= HttpContext.Current.Request.Url.Authority;//获取访问网址的主机名
if(!authority.Contains("www"))
{
string localPath= HttpContext.Current.Request.Url.LocalPath;//获取访问的具体页面
string query= HttpContext.Current.Request.Url.Query;//获取访问网址"?"后面的数据
authority="www."+authority;
HttpContext.Current.RewritePath(authority+localPath+query);
}
}
------解决方案--------------------
我错了,原来lz还发了这个帖子。
------解决方案--------------------
楼上的都不是301,web.config只能设置url转发,是无法设置301的。