使用角色和角色的基本软件设计问题会员资格
我正在查看 API 的过程中,看到以下两个调用:
API.Users.Roles.getAllRoles();
API.Admin.Roles.getAllRoles();
我想知道这些调用中的每一个是如何使用的 Web 程序的上下文。由于 Admin 和 Users 都是属性, 到底什么是得到;放;正在做?呼叫如何知道哪个管理员 (或用户)正在拨打电话?
我的预感是这与 API 类的方式有关 实例化(和会话?),但我希望能详细说明什么是 发生在这里所以我完全理解它。
(缩写的)类结构如下所示:
public class API()
{
public Admin Admin { get; private set; }
public Users Users { get; private set; }
}
public class Users
{
public Roles Roles { get; private set; }
...
}
public class Roles
{
public override string[] GetAllRoles()
{
...
}
}
提前致谢。
I am in the process of looking at an API and I see the following two calls:
API.Users.Roles.getAllRoles();
API.Admin.Roles.getAllRoles();
What I would like to know is how each of these call is used within
the context of a Web program. Since both Admin and Users are properties,
what exactly is the get; set; doing? How does the call know which Admin
(or user) is making the call?
My hunch is that this has something to do with how the API class is
instantiated (and session?) but I'd appreciate a walk-through on what is
going on here so I fully understand it.
The (abbreviated) class structure looks like the following:
public class API()
{
public Admin Admin { get; private set; }
public Users Users { get; private set; }
}
public class Users
{
public Roles Roles { get; private set; }
...
}
public class Roles
{
public override string[] GetAllRoles()
{
...
}
}
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它将检查当前主体 (HttpContext.Current.User.Identity.Name) 中的当前用户名,该主体根据设置使用表单/Windows 帐户,或者如果不在 Web 环境中,它将使用登录到的当前 Windows 用户系统。
It will check the current user name from the current principal (HttpContext.Current.User.Identity.Name) which uses forms/windows account depending on setup, or if not in the web environment, it will use the current windows user logged into the system.
对我来说,他们似乎有一个自定义角色提供程序,因此覆盖了 GetAllRoles 方法,以便可以从数据源获取角色。在没有看到更多细节的情况下,我只能假设,但是当用户注册时,他们可能会被分配一个特定的角色。然后,他们可以使用 Roles.IsUserInRole 方法来检测用户被分配的角色。 此处有更多关于自定义角色提供程序的信息,其中将解释为什么要使用方法被覆盖。
To me it seems that they have a custom role provider and are therefore overriding the GetAllRoles method so that the roles can be obtained from the datasource. Without seeing further details, I can only assume, but when a user registers, they're probably assigned a particular role. They can then use the
Roles.IsUserInRole
method to detect what role the user is assigned to. There's more on custom role providers here which will explain why methods are being overwritten.