2014-12-22 42 views
0

我的问题是这样的,我的www网页上有一个来自azure的错误404,但我只是输入domainname.com,然后工作,因为没有问题301使用global.asax从domainname.com重定向域名www.domainname.com

我想它被称为:

domainname.com并同时以www.domainname.com去工作,而不是拿出404错误做。

我已经尝试了她在Global.asax的

protected void Application_PreRequestHandlerExecute(Object sender, EventArgs e) 
{ 
    string currentUrl = HttpContext.Current.Request.Path.ToLower(); 
    if(currentUrl.StartsWith("http://mydomain")) 
    { 
    Response.Status = "301 Moved Permanently"; 
    Response.AddHeader("Location", currentUrl.Replace("http://mydomain", "http://www.mydomain")); 
    Response.End(); 
    } 
} 

注:MYDOMAIN必须站在.COM

回答