我正在尝试解决基于Windows的托管中的www和非www url问题, 我已经完成了下面给出的一些工作,但我需要检查它是否正确,它将解决我的问题。 使用经典的asp构建网站页面 (共享)使用go daddy在IIS 7.0上托管
我的global.asax编码如下
void Application_BeginRequest(object sender, EventArgs e)
{
string newUrl = string.Empty;
try
{
if (HttpContext.Current.Request.Url.AbsoluteUri.ToLower().StartsWith("http://itcorner.org.in"))
{
if (HttpContext.Current.Items["UrlRewritingNet.UrlRewriter.VirtualUrl"] != null)
newUrl = "http://www.itcorner.org.in" + HttpContext.Current.Items["UrlRewritingNet.UrlRewriter.VirtualUrl"].ToString();
else
newUrl = HttpContext.Current.Request.Url.AbsoluteUri.ToLower().Replace("http://itcorner.org.in", "http://www.itcorner.org.in");
Response.Status = "301 Moved Permanently";
Response.StatusCode = 301;
Response.StatusDescription = "Moved Permanently";
Response.AddHeader("Location", newUrl);
Response.End();
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
谢谢