MVC 5基于角色的身份验证 [英] MVC 5 Role Based Authentication

查看:128
本文介绍了MVC 5基于角色的身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我们的管理页面锁定只能使用管理员身份Asp.net(我们正在建设MVC5)。我可以得到[授权(用户=管理员)工作,但不能获得[授权(角色=管理员)的工作。

I am trying to lock down our "admin" page to only admins using Asp.net Identity (we are building in MVC5). I can get [Authorize(Users="admin")] to work but can not get [Authorize(Roles="Admin")] to work.

我已经建立在dbo.AspNetRoles表的作用,并然后通过配对GUID在aspnetroles表中的ID用户相关联的AspNetUserRoles的帐户。

I have created the role in the dbo.AspNetRoles table and then associated the account in the AspNetUserRoles by pairing the user GUID to the ID in the aspnetroles table.

在我的MVC previous版本已经看到你不得不进入web.config中添加一些行。谁能帮我指出了正确的方向?

I have seen in previous editions of MVC you have had to get into web.config to add some lines. Can anyone help point me in the right direction?

推荐答案

让你在你所要使用的角色在web.config中指定?

Have you specified in the web.config that you are going to use roles?

  <roleManager enabled="true" defaultProvider="AspNetSqlRoleProvider">
      <providers>
        <clear />
        <add name="AspNetSqlRoleProvider" connectionStringName="DefaultConnection" applicationName="/" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      </providers>
    </roleManager>

这篇关于MVC 5基于角色的身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆