void MvcApplication_PostAuthenticateRequest(object sender, EventArgs e)
        {
            var      authCookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName];
            var      context    = this.Context.Request.RequestContext.HttpContext;
            Market   market;
            Language language;

            // Set the culture
            if (authCookie != null)
            {
                var identity = CustomerIdentity.Deserialize(authCookie.Value);
                if (identity == null)
                {
                    FormsAuthentication.SignOut();
                    return;
                }
                else
                {
                    HttpContext.Current.User = new GenericPrincipal(identity, null);
                    Context.User             = new GenericPrincipal(identity, null);

                    // set market to user's current market
                    market = Identity.Customer.Market;
                    // get the default language based on user market
                    var defaultLanguage = Identity.Customer.Language;
                    // get the selected culture (default to user's preferred market language)
                    var selectedCultureCode = GlobalUtilities.GetSelectedCultureCode(context, defaultLanguage.CultureCode);
                    // set the language based on selection
                    language = GlobalUtilities.GetLanguage(selectedCultureCode, market);
                }
            }
            else
            {
                // get the market based on selection
                market = GlobalUtilities.GetCurrentMarket(context);
                // get the default language based on market
                var defaultLanguage = GlobalUtilities.GetLanguage(null, market);
                // get the selected culture (default to current market default language)
                var selectedCultureCode = GlobalUtilities.GetSelectedCultureCode(context, defaultLanguage.CultureCode);
                // set the language based on selection
                language = GlobalUtilities.GetLanguage(selectedCultureCode, market);
            }

            // Set the culture (date, number, currency formats)
            GlobalUtilities.SetCurrentCulture(market.CultureCode);
            // set site language
            GlobalUtilities.SetCurrentUICulture(language.CultureCode);
        }
Example #2
0
        void MvcApplication_PostAuthenticateRequest(object sender, EventArgs e)
        {
            var authenticated = false;

            var authCookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName];

            // Set the culture
            if (authCookie != null)
            {
                var identity = CustomerIdentity.Deserialize(authCookie.Value);
                if (identity == null)
                {
                    FormsAuthentication.SignOut();
                }
                else
                {
                    authenticated = true;

                    HttpContext.Current.User = new GenericPrincipal(identity, null);
                    Context.User             = new GenericPrincipal(identity, null);


                    // Set the culture codes
                    GlobalUtilities.SetCurrentCulture(Identity.Customer.Market.CultureCode);
                }
            }
            else
            {
                var cultureCookie = HttpContext.Current.Request.Cookies[GlobalSettings.Globalization.LanguageCookieName];
                if (cultureCookie != null && cultureCookie.Value.IsNotNullOrEmpty())
                {
                    GlobalUtilities.SetCurrentCulture(cultureCookie.Value);
                }
            }

            // Set the language
            System.Threading.Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture(Exigo.GetSelectedLanguage());
        }