自定义角色提供者的问题

发布于 2024-10-06 20:17:19 字数 1625 浏览 4 评论 0原文

此堆栈跟踪是由于错误“提供程序名称不能为 null 或为空。 “

[ArgumentException:提供程序名称不能为 null 或为空。] System.Web.Security.Roles.Initialize() +2230205 System.Web.Security.RoleManagerModule.OnLeave(对象源,EventArgs eventArgs)+68 System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +148 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& CompletedSynchronously) +75

本质上,我正在创建继承 SqlRoleProvider 类的自己的自定义角色提供程序,我正在成功调用初始化,并已确认它成功执行了我的代码中的所有操作,但是.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”可以在业务框架中使用不用担心破坏任何东西并允许替换后端源(例如角色数据可以来自任何地方)。

这里还有很多事情要做,但本质上整个应用程序框架/业务对象层都以这种方式使用提供者从任何来源向核心业务逻辑“提供”数据。

This stack trace comes as a result of an error that reads "Provider name cannot be null or empty.
"

[ArgumentException: Provider name cannot be null or empty.]
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

Essentially I am creating my own custom role provider that inherits the SqlRoleProvider class, i'm calling initialize successfully and have confirmed that it sucessfully does everything in my code but something in .Net is clearly not being initialized right as the "Roles" object that I can't inherit is causing me some headaches ...

any ideas?

Ok my solution is layered which means i need to provide security through the business object layer too ... in order to do that I define the following:

--- EDIT 1 ---

My Code:

In main assembly:

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);
     }
}

In provider assembly:

public class C20SqlRoleDataProvider : SqlRoleProvider
{
      // code omitted
}

At this point I would expect to be able to use anything that the base class "RoleProvider" defines by making the calls on prov. ...

I have omitted the extra code but there is basically all the methods that are marked abstract from the RoleProvider class in the class "C20RoleProvider".

I know it looks a bit wierd but what im looking to do is separate business logic from data aquisition in the provider, with the data provider being anything (through my reflection code) the business logic class "C20RoleProvider" can be use in the business framework without fear of breaking anything and allow for replacement back end sources (e.g. role data can come from anywhere).

There's a lot more going on here but essentially the entire application framework / business object layer uses providers in this fashion to "provide" data to core business logic from any source.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

红焚 2024-10-13 20:17:19

好吧,我做了一些挖掘...事实证明,我没有传回“名称”属性,该属性实际上没有在任何地方引用...

修复是这样的...

public class C20RoleProvider : RoleProvider 
{ 
     private C20SqlRoleDataProvider prov; 

     public string Name
     {
         get {return prov.Name;}
     }

     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); 
     } 
} 

奇怪的是,这似乎不是在网络上任何地方都知道。

Ok i did some digging ... turns out that I wasn't passing back that "Name" property which is not actually referred to anywhere ...

The fix goes something like this ...

public class C20RoleProvider : RoleProvider 
{ 
     private C20SqlRoleDataProvider prov; 

     public string Name
     {
         get {return prov.Name;}
     }

     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); 
     } 
} 

Weird that this doesn't seem to be known anywhere on the net.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文