ASP.NET MVC 5 Active Directory身份验证获取用户组

时间:2015-10-09 14:04:04

标签: c# asp.net asp.net-mvc ou

我有一个授权针对活动目录的应用程序,这非常有效。现在我要做的是获取登录组名称的用户。

我在这里有这个方法:

[HttpPost]
        public ActionResult Login(LoginClass model, string ReturnUrl)
        {

            if (ModelState.IsValid)
            {
                if (Membership.ValidateUser(model.UserName, model.Password))
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                    if (Url.IsLocalUrl(ReturnUrl) && ReturnUrl.Length > 1 && ReturnUrl.StartsWith("/")
                        && !ReturnUrl.StartsWith("//") && !ReturnUrl.StartsWith("/\\"))
                    {
                        return Redirect(ReturnUrl);
                    }
                    else
                    {
                        string[] test = Roles.GetRolesForUser();
                        return RedirectToAction("Index", "Home");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect");
                }
            }

            return RedirectToAction("Index", "Home");
        } 

现在这一行:string[] test = Roles.GetRolesForUser();返回空。我放了一个断点,发现了这条消息:

The Role Manager feature has not been enabled

我还将此添加到我的web.config:

<roleManager enabled="true" />

在system.web里面配置

我做错了什么,我知道这些群体存在,我只是无法获得它们或者如何获得用户OU(组织单位)

0 个答案:

没有答案
相关问题