2010-01-21 27 views
5

i herşeyi yönlendirmek için Global.asax talebini başlamak kullanabilirsiniz www.domain için etki alanından yönlendirme,Küresel 301

www.mydomain.domain için mydomain.domain den?

Eğer bu doğruysa, bunu nasıl yapabilirim?

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

Değişiklikler BeginRequest olay kullanmak ve HttpContext yerine HttpContext.Current.Request.Url için CURRENTURL ayarlamak için vardı:

cevap

4
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(); 
    } 
} 
+0

Merhaba, ben Ön koşullar işleyicisi Global.asax içinde olmasaydı bulundu yüzden bunu ekledi. Ama olay hata ayıklama modunda çalışmıyor ... Burada başka bir şey yapıyorum? – OrElse

+0

'PreRequestHandlerExecute 'öğesini' BeginRequest 'olarak değiştirdiğinizde mi ateş ediyor? –

+0

Yeap! BeginRequest her isteğinde patlar – OrElse