Esempio n. 1
0
        private string GenerateEncryptedTicket(User user, string cookieName, bool persistent)
        {
            if (user == null)
            {
                return(null);
            }

            var serializeModel = new CustomPrincipalSerializeModel
            {
                UserId         = user.Id,
                OrganizationId = user.OrganizationId,
                IsConfirmed    = user.IsConfirmed,
                Roles          = _userService.GetRoles(user),
                DisplayName    = user.FirstName
            };

            var serializer = new JavaScriptSerializer();
            var userData   = serializer.Serialize(serializeModel);

            var authTicket = new FormsAuthenticationTicket(
                CookieVersion,                  // version
                cookieName,                     // name
                DateTime.UtcNow,                //created
                DateTime.UtcNow.AddMinutes(60), // expires
                persistent,                     // persistent?
                userData                        // user data
                );

            return(FormsAuthentication.Encrypt(authTicket));
        }
        private string GenerateEncryptedTicket(User user, string cookieName, bool persistent)
        {
            if (user == null) return null;

              var serializeModel = new CustomPrincipalSerializeModel
            {
              UserId = user.Id,
              OrganizationId = user.OrganizationId,
              IsConfirmed = user.IsConfirmed,
              Roles = _userService.GetRoles(user),
              DisplayName = user.FirstName
            };

              var serializer = new JavaScriptSerializer();
              var userData = serializer.Serialize(serializeModel);

              var authTicket = new FormsAuthenticationTicket(
            CookieVersion, // version
            cookieName, // name
            DateTime.UtcNow, //created
            DateTime.UtcNow.AddMinutes(60), // expires
            persistent, // persistent?
            userData // user data
            );

              return FormsAuthentication.Encrypt(authTicket);
        }