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 suce开发者_StackOverflow中文版ssfully 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.
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.
精彩评论