Example #1
0
        public static void SetPrincipal(HttpContextBase httpContext)
        {
            Principal principal = null;

            if (httpContext.Request.IsAuthenticated)
            {
                var identity = (FormsIdentity)httpContext.User.Identity;

                try
                {
                    var userProfile = SecurityTokenHelper.FromString(((FormsIdentity)identity).Ticket.UserData).UserData;
                    // UserHelper.UpdateLastActiveOn(userProfile);
                    principal = new AuthenticatedPrincipal(identity, userProfile);
                }
                catch
                {
                    //TODO: Log an exception
                    FormsAuthentication.SignOut();
                    principal = new AnonymousPrincipal(new GuestIdentity());
                }
            }
            else
            {
                principal = new AnonymousPrincipal(new GuestIdentity());
            }

            httpContext.User = principal;
        }
Example #2
0
        public static void SetPrincipal(HttpContextBase httpContext)
        {
            Principal principal = null;

            if (httpContext.Request.IsAuthenticated)
            {
                var identity = (FormsIdentity)httpContext.User.Identity;

                try
                {
                    var userProfile = SecurityTokenHelper.FromString(((FormsIdentity)identity).Ticket.UserData).UserData;
                    // UserHelper.UpdateLastActiveOn(userProfile);
                    principal = new AuthenticatedPrincipal(identity, userProfile);
                }
                catch
                {
                    //TODO: Log an exception
                    FormsAuthentication.SignOut();
                    principal = new AnonymousPrincipal(new GuestIdentity());
                }
            }
            else
                principal = new AnonymousPrincipal(new GuestIdentity());

            httpContext.User = principal;
        }