此堆栈跟踪是由于“提供程序名称不能为空或为空”错误而出现的。
[ArgumentException:提供程序名称不能为 null 或为空。] System.Web.Security.Roles.Initialize() +2230205 System.Web.Security.RoleManagerModule.OnLeave(Object source, EventArgs eventArgs) +68 System.Web.SyncEventExecutionStep.System .Web.HttpApplication.IExecutionStep.Execute() +148 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
本质上,我正在创建自己的自定义角色提供程序,它继承了 SqlRoleProvider 类,我成功调用了 initialize 并确认它成功地完成了我的代码中的所有操作,但是 .Net 中的某些内容显然没有被初始化为“角色”对象我不能继承让我有些头疼...
有任何想法吗?
好的,我的解决方案是分层的,这意味着我也需要通过业务对象层提供安全性......为了做到这一点,我定义了以下内容:
--- 编辑 1 ---
我的代码:
在主装配中:
public class C20RoleProvider : RoleProvider
{
private C20SqlRoleDataProvider prov;
C20RoleProvider()
{
// this code is actually using some reflection based on config files
// i have simplified this to illustrate the problem im having ...
prov = new C20SqlRoleDataProvider();
}
public override void Initialize(string name, NameValueCollection config)
{
prov.Initialize(name, config);
}
}
在提供程序组装中:
public class C20SqlRoleDataProvider : SqlRoleProvider
{
// code omitted
}
在这一点上,我希望能够通过调用 prov 来使用基类“RoleProvider”定义的任何东西。...
我省略了额外的代码,但基本上所有方法都被标记为“C20RoleProvider”类中的 RoleProvider 类的抽象方法。
我知道它看起来有点奇怪,但我想做的是将业务逻辑与提供者中的数据采集分开,数据提供者可以是任何东西(通过我的反射代码)业务逻辑类“C20RoleProvider”可以在业务框架中使用不用担心破坏任何东西并允许替换后端源(例如角色数据可以来自任何地方)。
这里还有很多事情要做,但基本上整个应用程序框架/业务对象层都以这种方式使用提供者从任何来源“提供”数据给核心业务逻辑。