protected void Session_Start() { Session["LastUrl"] = Session["Url"] = Request.Url.AbsoluteUri; Session["Language"] = null; // Use System language id string languageId = Request.UserLanguages[0].Substring(0, 2); try { Session["Language"] = Language.LanguageDictionary[languageId]; } catch { Session["Language"] = Language.LanguageDictionary["en"]; } // Use User language id if (User.Identity.IsAuthenticated) { DB_Examen_P5_BramEntities db = new DB_Examen_P5_BramEntities(); AspNetUser user = db.AspNetUsers.First(u => u.UserName == User.Identity.Name); Session["Language"] = Language.LanguageDictionary[user.LanguageId]; } // Default if (Session["Language"] == null) { Session["Language"] = Language.LanguageDictionary["en"]; } }
public static void Initialise() { DB_Examen_P5_BramEntities db = new DB_Examen_P5_BramEntities(); // Initialise Languages Language.AllLanguages = db.Languages.OrderBy(lang => lang.Name).ToList(); Language.Languages = Language.AllLanguages.Where(lang => lang.SystemLanguage).ToList(); Language.LanguageDictionary = new Dictionary <string, Language>(); foreach (Language lan in Language.AllLanguages) { Language.LanguageDictionary[lan.Id] = lan; } }