gpt4 book ai didi

c# - 具有应用程序名称 IsInRole 的自定义 IPrincipal

转载 作者:行者123 更新时间:2023-11-30 16:23:21 26 4
gpt4 key购买 nike

我正在实现一个我想在多个应用程序中使用的自定义 IPrincipal。我有 2 个关于 IsInRole 方法的问题...

1) 是否建议我将自定义 RoleProvider 与自定义 IPrincipal 一起使用?我总是可以将检查用户角色的逻辑放在继承自 IPrincipal 的类中。

类似于:

public class SSDSPrincipal : IPrincipal
{
public SSDSPrincipal(SSDSIdentity identity)
{
this.Identity = identity;
}

public IIdentity Identity {get;private set;}

public bool IsInRole(string role)
{
string[] roles = Roles.Providers["SSDSRoleProvider"].GetRolesForUser(Identity.Name);
return roles.Any(s => role.Contains(s));
}
}

2) 因为我想在多个 MVC3 应用程序中使用它。存储应用程序名称的最佳位置在哪里?我需要能够手动设置它。

public bool IsInRole(string role)
{
string applicationName = [where can I store this globally for my asp.net mvc3 app]
return AreTheyInARoleForThisApplication(applicationName, role);
}

最佳答案

我想说您可以自由使用任何您想要的技术来查明某个用途是否在某个角色中。 RoleProvider 在这里不是必须的。

您不能将应用程序名称作为构造函数参数传递,然后将其存储在成员中吗?

关于c# - 具有应用程序名称 IsInRole 的自定义 IPrincipal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11646580/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com