.NET 角色、成员资格、FormsAuthentication、MVC3
我正在使用 MVC3 创建一个 Web 应用程序。我有一个数据库,其中包含我在应用程序中使用的所有表(包括用户和角色表,这是此问题的焦点)。
我已经(非常快地)设置为使用 SetAuthCookie 对用户进行身份验证。然而,由于我的应用程序具有不同的角色,我还需要能够在用户访问特定控制器之前查明用户是否处于特定角色。
在过去的几天里,我一直在尝试从这里和一般的在线搜索中实施各种解决方案,但失败了。讨论的主题包括 FormsAuthentication、IIdentity、IPrincipal、MembershipProvider、RoleProvider。经过几次失败的尝试后,我对一切都感到完全困惑。
过去,我使用过 ASPNET 会员数据库的默认帐户内容,并且由于我根本不需要接触它,因此没有任何问题。但我希望这次所有的表都在同一个数据库中。我还希望可以用 [Authorize]、[Role="Sysadmin"] 等来装饰控制器。
我知道这个问题和类似的问题被问了很多,并且有几个可用的资源涵盖了上述主题,但问题是解决方案是相互冲突的,或者假设其他相关领域的知识,或者存在非标准类,甚至在某些情况下“为了简单起见”提供了有缺陷的解决方案。
回顾一下:
- 我有一个空白的 MVC3 项目。
- 我有一个包含用户表和角色表的数据库(每个用户可以有一个角色)。
- 我想用 [Authorize]、[Role="Sysadmin"] 装饰控制器
- 我不在乎解决方案有多复杂。我愿意花费尽可能多的时间来获得最安全、最高效的解决方案。
提前致谢
I am creating a web application using MVC3. I have one database which contains all of the tables I use in the application (including a Users and Roles table, which are the focus of this question).
I have already set it up (very quickly) to Authenticate the user using SetAuthCookie. However as my application has different roles, I also need to be able to find out if the user is in a specific role before they can access specific controllers.
I have spent the last few days trying and failing to implement various solutions from here and general online searches. Topics of discussion have been FormsAuthentication, IIdentity, IPrincipal, MembershipProvider, RoleProvider. And after several failed attempts I am completely confused by everything.
In the past I have used the default accounts stuff using the ASPNET Membership DB, and since I didn't have to touch it at all, had no problems. But I would prefer all of my tables were in the same DB this time around. I would also prefer that I can decorate the controllers with [Authorize], [Role="Sysadmin"] etc.
I am aware that this and similar questions are asked a lot and that there are several resources available which cover the topics described above, but the problem is that the solutions are conflicting, or assume knowledge of other related fields, or the presence of non-standard classes, and even in some cases provide a flawed solution "for simplicity's sake".
So to recap:
- I have a blank MVC3 project.
- I have a Database with my Users Table and Roles Table (each user can have one role).
- I want to decorate the controllers with [Authorize], [Role="Sysadmin"]
- I do not care how complex the solution is. I am willing to spend as much time as necessary to get the most secure and efficient solution.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以编写自定义会员资格提供程序,这里有一个解释更多信息的链接:
MVC 3客户会员提供商
You can write custom membership providers, here is a link that explains more:
MVC 3 Customer Membership providers