加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc-4 – 使用活动目录角色提供者MVC4进行授权

发布时间:2020-12-15 22:52:17 所属栏目:asp.Net 来源:网络整理
导读:我正在构建一个用于企业环境内部使用的MVC4应用程序.我使用 Windows身份验证,这可以正常工作,但是我使用Active Directory组作为授权角色有麻烦. 我的Web.config看起来像这样: authentication mode="Windows" / roleManager enabled="true" defaultProvider=
我正在构建一个用于企业环境内部使用的MVC4应用程序.我使用 Windows身份验证,这可以正常工作,但是我使用Active Directory组作为授权角色有麻烦.

我的Web.config看起来像这样:

<authentication mode="Windows" />        
<roleManager enabled="true" defaultProvider="AspNetWindowsTokenRoleProvider">
  <providers>
    <clear />
    <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
  </providers>
</roleManager>        
<authorization>
  <deny users="?" />    
</authorization>

当我使用用户授权它工作正常:

[Authorize(Users = @"DOMAINUser1,DOMAINUser2")]
public ActionResult Create()
{
    return View();
}

但是当我使用角色时,只是不让该组中的用户访问此操作:

[Authorize(Roles = @"DomainGroup")]
public ActionResult Create()
{
    return View();
}

我也尝试指定没有域的组,因为我在其他回复中阅读,但没有运气…我想我在Web.config中缺少一些东西,但我不知道什么

我正在避免使用自定义角色提供程序,因为MVC4应该在没有自定义角色提供程序的情况下实现(或者至少这就是我的想法)

谁能帮我这个?

提前致谢!

解决方法

我发现是哪个问题.在阅读有关machine.config here的一些信息后,我检查了我已经应用了正确的配置.

Fianlly我得到它这样工作:

[Authorize(Roles = "DomainGroup")]
public ActionResult Create()
{
    return View();
}

问题是我打字的方式.

我希望这可以帮助别人.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读