2011-02-09 35 views

回答

0

您時,這可能引起問題可以將此代碼用於Global.asax文件中的任何asp.net應用程序:

void Application_BeginRequest(object sender, EventArgs e) 
{ 
    string FromHomeURL = http://yourdomain.com;  
    string ToHomeURL = http://www.yourdomain.com; 

    if(HttpContext.Current.Request.Url.ToString().ToLower().Contains(FromHomeURL)) 
    { 
     HttpContext.Current.Response.Status = "301 Moved Permanently"; 
     HttpContext.Current.Response.AddHeader("Location", 
     Request.Url.ToString().ToLower().Replace(FromHomeURL, ToHomeURL)); 
    } 
} 
相關問題