简体   繁体   English

Asp.net MVC表单身份验证防止创建时自动记录用户

[英]Asp.net mvc Forms Authentication Prevent user from been automatically logged when created

Asp.net mvc 4 application, with Forms Authentication, I have a admin role who adds users to the application, but when I create a new user it automatically logs the new created user in, how can i prevent this? Asp.net mvc 4应用程序,具有窗体身份验证,我具有将用户添加到该应用程序的管理员角色,但是当我创建新用户时,它将自动将新创建的用户登录,该如何防止呢?

here's my register action in the account controller 这是我在帐户控制器中的注册操作

      [HttpPost]
    public ActionResult Register(string username, string password)
    {
        WebSecurity.CreateUserAndAccount(username, password);
        Roles.AddUserToRole(username, "Mechanic");
        FormsAuthentication.SetAuthCookie(username, false);
        return new HttpStatusCodeResult(HttpStatusCode.OK); 
    }

Try this: 尝试这个:

 [HttpPost]
public ActionResult Register(string username, string password)
{
    WebSecurity.CreateUserAndAccount(username, password);
    Roles.AddUserToRole(username, "Mechanic");

    return new HttpStatusCodeResult(HttpStatusCode.OK); 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM