ASP.NET MVC 多个不同的用户组 - 授权/身份验证
我已经做了很多研究来尝试实现这一目标,但我还没有真正找到明确的“最佳方法”来实现这一目标。 我正在开发一个拥有许多不同用户组的应用程序,本质上它允许多个公司使用同一个应用程序 - 非常像谷歌应用程序。 以下是我的意思的一个示例:
在 Google Apps 中 - 用户转到 mail.company.com -> 它们会被重定向到 mail.google.com/a/company.com。
我了解如何使用 CNAME 记录,并且可以在将主机重定向到我的应用程序后从域中提取主机,以便我的应用程序将 URL 转换为 my.app.com/company.com。 此外,我的所有路由都已配置为采用 {companyURL} 属性。
那么现在的问题是,如何提供“动态”角色检查? 创建一个自定义角色提供程序来设置用户的公司名称和该公司内的其他角色似乎很容易,但我不知道如何将 {companyURL} 获取到授权过滤器。 授权过滤器中是否可以有一个动态变量,或者我是否必须在每个控制器/操作中检查它(使用某些函数)? 或者还有另一种我可能还没有想到的方法来实现这一点?
谢谢
I have done a lot of research on trying to accomplish this, but I have not really found a clear cut "best way" to accomplish this. I am working on an application that has many distinct groups of users, essentially it allows multiple companies to use the same application - very much like Google apps. Here is an example of what I mean:
In Google Apps - user goes to mail.company.com -> they are redirected to mail.google.com/a/company.com.
I understand how to use CNAME records and can pull the host from the domain once it has been redirected to my app so that my app would translate the URL to my.app.com/company.com. Also, all of my routes have been configured to take a {companyURL} attribute.
So the issue now becomes, how do I provide "dynamic" role checking? It seems that it would be easy enough to create a custom role provider that sets the user's company name and other roles withing that company, but I don't know how to get the {companyURL} to the authorization filter. Is it possible to have a dynamic variable in the authorization filter or do I have to check this inside each controller/action (using some function)? Or is there another method to accomplish this that perhaps I have not thought of yet?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您已经在另一个系统中定义了角色,我会使用自定义角色提供程序类或自定义 IAuthenticationFilter。
I would go with a custom role provider class, or a custom IAuthenticationFilter if you already have roles defined in another system.