[英]How do I create a user through membership without being logged into their account after creation?
I'm having a logged in user create another user (different roles) using Membership.CreateUser. 我有一个登录用户,使用Membership.CreateUser创建另一个用户(不同的角色)。 After creating the user, the logged in user automatically gets the boot and the newly created user is logged in.
创建用户后,已登录的用户将自动获得启动,并且新创建的用户已登录。
The goal would be to have the logged in user create a new user and continue working within the app being logged in under their own credentials. 目标是让登录用户创建一个新用户,并继续使用自己的凭据在正在登录的应用程序内工作。
I'm not sure how to change this. 我不确定如何更改此设置。 Any help would be appreciated.
任何帮助,将不胜感激。
Here is my code: 这是我的代码:
[HttpPost]
public ActionResult RegisterClientContact(RegisterClientContactViewModel model)
{
if (ModelState.IsValid)
{
//Create Generic password - First initial Last initial 1234
string genericPassword = model.FirstName.Substring(0, 1).ToLower() + model.LastName.Substring(0, 1).ToLower() + "1234";
//Attempt to register the Client Contact
MembershipCreateStatus createStatus;
Membership.CreateUser(model.Email, genericPassword, model.Email, null, null, true, null, out createStatus);
if (createStatus == MembershipCreateStatus.Success)
{
Roles.AddUserToRole(model.Email, "Client");
FormsAuthentication.SetAuthCookie(model.Email, false /*create persistent cookie*/);
Person person = new Person();
person.FirstName = model.FirstName;
person.LastName = model.LastName;
person.Email = model.Email;
person.Phone = model.Phone;
person.Active = true;
db.Persons.Add(person);
db.SaveChanges();
ClientContact clientPerson = new ClientContact();
clientPerson.ClientPersonId = person.Id;
clientPerson.Title = model.Title;
clientPerson.ClientId = model.ClientId;
db.ClientPersons.Add(clientPerson);
db.SaveChanges();
return RedirectToAction("Index", "ClientContact");
}
}
return View("An Error has occured");
}
Try deleting these two lines. 尝试删除这两行。
Roles.AddUserToRole(model.Email, "Client");
FormsAuthentication.SetAuthCookie(model.Email, false /*create persistent cookie*/);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.