2016-04-06 16 views
1

Url'de dil yoksa, dili varsayılan web sitesi diline değiştirmek için kod ekledim. Bu yüzden eğer ben şu web sitesinde oturuyorum: http://mywebsite/da sonra "da" dil kodunu kaldırdım, ingilizce olan varsayılan web sitesi diline geçiyorum. Sorun, bazı sayfalarda, dilin varsayılan web sitesi dilini ayarlamak için ikinci sayfanın yenilenmesini gerektiriyor, çerez dilinde bile doğru şekilde değiştirildi. Bu benim kodudur:Dili Varsayılan Dil Olarak Sıfırlar Nasıl

web.config'de ben system.webServer/modules altında sonuna int bu katma yüzden, bunun için modül oluşturuldu:

<add name="ResetLanguageModule" type="MyWebsite.Modules.ResetLanguageModule, MyWebsite.Web" /> 

Benim Kod:

public void Init(HttpApplication app) 
{ 
    app.BeginRequest += Application_BeginRequest; 
} 

private static void Application_BeginRequest(object sender, EventArgs e) 
{ 
    // if user is on the root or the url does not contians language in url 
    if (HttpContext.Current.Request.RawUrl == "/" || !HttpContext.Current.Request.RawUrl.Contains(string.Format("/{0}/", Sitecore.Context.Language.Name))) 
    { 
     ResetLanguage(); 
    } 
} 
private static void ResetLanguage() 
{ 
    // change language to default one if the comming request is a page. 
    if (Sitecore.Context.Page != null && 
     Sitecore.Context.Site != null && 
     Sitecore.Context.Language.Name != Sitecore.Context.Site.Language) 
    { 
     Language currentSiteLanugage; 
     if (Language.TryParse(Sitecore.Context.Site.Language, out currentSiteLanugage)) 
     { 
      Sitecore.Context.SetLanguage(currentSiteLanugage, true); 
     } 
    } 
} 
+3

Kodunuzu 'httpRequestBegin' boru hattına taşımayı denediniz mi? Varsayılan olarak 'LanguageResolver'? –

+1

Sitecore LanguageResolver'dan önce taşıdım ve şu anda çalışıyor, teşekkürler @MarekMusielak –

cevap

4

Sen dönüştürmek gerekir senin Bir işlemciye dönüştürün ve httpRequestBegin boru hattına ekleyin.

Varsayılan olarak Sitecore LanguageResolver'dan eklediğinizden emin olun.

İlgili konular