ASP.NET 会员资格
我正在编写一个 MVC 应用程序,使用 ASP.Net 成员资格来确保安全。该应用程序将允许多个网站从同一应用程序和数据库运行。
该应用程序上运行的网站将完全相互独立。这些网站的用户只能访问他们的网站。
如果我使用一个 web.config、一个 MVC 应用程序和一个数据库,我可以使用 ASP.NET 成员身份实现站点特定的安全性吗?
大概我只有一个应用程序密钥,因此不会能够使用它来区分站点。我考虑过使用角色,但会将角色公开给网站管理员 - 并且不希望管理员为自己的用户添加/配置不同网站的角色。
这个潜在的问题刚刚发生在我身上,因此我们将不胜感激任何帮助。
I'm writing an MVC application, using ASP.Net Membership for security. The application will allow multiple websites to run from the same app and database.
The websites running on the app will be completely independent from each other. The users of those sites will have access to their site only.
If I'm using one web.config, one MVC app and one database, can I achieve site specific security using ASP.NET membership?
Presumably I'll only have one application key so won't be able to use that to differentiate between sites. I thought about using Roles but will be exposing roles to site administrators -- and don't want admins to add / configure roles for a different site to their own users.
This potential problem has only just occurred to me so any help will be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
角色提供程序使用一个 ApplicationName 属性来过滤角色。尝试在获取角色之前设置该属性。
像这样的东西应该有效:
我还没有尝试过,它是一个静态属性,可能会给你带来奇怪的结果,所以要小心。最好的方法是实现您自己的提供程序,这样您就可以执行类似
Roles.IsUserInRole("some.user","admin","MyAppName")
的操作。There is an ApplicationName property that the roles provider uses to filter roles on. Try setting that property before fetching roles.
Something like this should work:
I haven't tried this, it is a static property and could give you weird results, so be careful. The best way to do this would be to implement your own provider so you could do something like
Roles.IsUserInRole("some.user","admin","MyAppName")
.您可以将它们作为主站点的子站点(在那里设置 web.config),因此身份验证会渗透到子站点。
You could you have them as sub sites of the main site (with web.config setup there) and therefore, the authentication permeates through the sub-sites.