简体   繁体   English

AspNet.Identity角色管理

[英]AspNet.Identity role Management

I am using Asp.net 4.5.1 webForm application with EF codefirst. 我正在使用带有EF codefirst的Asp.net 4.5.1 webForm应用程序。 for Authentication I am using Microsoft.AspNet.Identity. 对于身份验证,我使用的是Microsoft.AspNet.Identity。 I want in the loging page after I check that user is correct also check user's role. 我要在检查用户正确之后在登录页面中还要检查用户的角色。 if user is in admin role, send user to admin folder(page) or if user in users role send the user to users folder(page). 如果用户具有管理员角色,则将用户发送到admin文件夹(页面),或者如果用户具有用户角色,则将用户发送到用户文件夹(页面)。 how can I check user is in Admin role or not? 如何检查用户是否具有管理员角色?

this is my Login code: 这是我的登录代码:

protected void btnLogin_Click(object sender, EventArgs e)
    {
        if (IsValid)
        {
            // Validate the user password
            var manager = new UserManager();
            ApplicationUser user = manager.Find(inputEmail.Text, inputPassword.Text);
            if (user != null)
            {
                IdentityHelper.SignIn(manager, user, false);

                if (//user is in admin role)
                {
                    Response.Redirect("UserPage");
                }
                else
                {
                    Response.Redirect("AdminPage");
                }


            }
            else
            {
                //Show error message that User is Incorrect
            }
        }
    }

Try using UserManager.IsInRole(User.Identity.GetUserId(), "RoleName") 尝试使用UserManager.IsInRole(User.Identity.GetUserId(), "RoleName")

Moreover refer to : Understand IsInRole with character case 另外参考: 用字符大小写理解IsInRole

Tip: Try exploring any assembly in "Object Browser" (Ctrl+Alt+J) in Visual Studio. 提示:尝试在Visual Studio的“对象浏览器”(Ctrl + Alt + J)中浏览任何程序集。

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

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