Agribusiness.Web.Models.FormsAuthenticationService.SignIn C# (CSharp) Method

SignIn() public method

public SignIn ( string userName, bool createPersistentCookie ) : void
userName string
createPersistentCookie bool
return void
        public void SignIn(string userName, bool createPersistentCookie)
        {
            if (String.IsNullOrEmpty(userName)) throw new ArgumentException("Value cannot be null or empty.", "userName");

            FormsAuthentication.SetAuthCookie(userName, createPersistentCookie);
        }

Usage Example

        public ActionResult Edit(Guid? id, PersonEditModel personEditModel, HttpPostedFileBase profilepic)
        {
            User user = null;

            // admin is trying to edit, authorize them
            if (id.HasValue)
            {
                // current user must be in User role
                if (Roles.IsUserInRole(RoleNames.User))
                {
                    user = _userRepository.GetNullableById(id.Value);
                }
            }
            else
            {
                user = Repository.OfType<User>().Queryable.Where(a => a.LoweredUserName == CurrentUser.Identity.Name.ToLower()).FirstOrDefault();
            }

            if (user == null)
            {
                return this.RedirectToAction<ErrorController>(a => a.NotAuthorized());
            }

            //var seminarPerson = _seminarPersonRepository.GetNullableById(personEditModel.SeminarPersonId);
            var person = SetPerson(personEditModel, null, ModelState, user.Person, profilepic);

            var membership = user.Membership;
            membership.SetEmail(personEditModel.Email);

            if (ModelState.IsValid)
            {
                _personRepository.EnsurePersistent(person);
                _membershipRepository.EnsurePersistent(membership);

                Message = string.Format(Messages.Saved, "Person");

                if (personEditModel.UserName != CurrentUser.Identity.Name.ToLower())
                {
                    user.SetUserName(personEditModel.UserName);
                    _userRepository.EnsurePersistent(user);

                    var formsService = new FormsAuthenticationService();
                    formsService.SignOut();
                    formsService.SignIn(user.LoweredUserName, false);
                }

                // send to crop photo if one was uploaded
                if (profilepic != null) return this.RedirectToAction(a => a.UpdateProfilePicture(person.Id, null, true));
            }

            var viewModel = PersonViewModel.Create(Repository, _firmService, Site, null, person, user.Email);
            return View(viewModel);
        }
FormsAuthenticationService