public static void Initialize()
 {
     var cookie = new AppCookie();
     var val = cookie.Retreive();
     if (!HttpContext.Current.User.Identity.IsAuthenticated)
     {
         HttpContext.Current.User = new GenericPrincipal(
             new GenericIdentity(val.AnonymId, AnonymousType),
             SecurityConfig.Config.AnonymRoles.ToArray());
     }
     if (!string.IsNullOrEmpty(val.AnonymId)) return;
     val.AnonymId = Guid.NewGuid().ToString();
     cookie.Update(val);
 }
Example #2
0
        public static void InitalizeCulture()
        {
            AppCookie appCookie = new AppCookie();
            AppCookieModel cookie = appCookie.Retreive();

            //Culture already set in cookie... good
            if (cookie.Culture != null)
            {
                if (SetCulture(cookie.Culture))
                    return;
            }

            // set first culture from Request.UserLanguages that maches config cultures list
            if (HttpContext.Current != null && HttpContext.Current.Request.UserLanguages != null)
            {
                foreach (var l in HttpContext.Current.Request.UserLanguages)
                {
                    var s = l.Split(';')[0];
                    if (s == null) continue;
                    if (!SetCulture(s)) continue;
                    cookie.Culture = s;
                    appCookie.Update(cookie);
                    return;
                }
            }

            // no culture in Request.UserLanguages maches config cultures list, set one from current thread if maches config
            if (SetCulture(Thread.CurrentThread.CurrentUICulture.Name))
            {
                cookie.Culture = Thread.CurrentThread.CurrentUICulture.Name;
                appCookie.Update(cookie);
                return;
            }

            // current thread does not mache config cultures list, set the first one from config if exists
            string c = Config.Cultures.FirstOrDefault();
            if (c == null) return;
            SetCulture(c);
            cookie.Culture = c;
            appCookie.Update(cookie);
        }