Is it possible to use the built in SqlRoleProvider along with a custom membership provider? How would this be accomplished?
@mellamokb
Merge certain aspects of both of them? NO
Use them side-by-side at开发者_JAVA百科 the same time? YES (hence the "use the built in SqlRoleProvider along with a custom membership provider" part of my question)
Read roles from both? What does a membership provider have to do with reading roles?
Authenticate against both of them simultaneously? What does a role provider have to do with a authentication?
What does a membership provider have to do with reading roles?
Nothing.
What does a role provider have to do with a authentication?
Nothing
Yes, you can surely use SqlRoleProvider along-side with your custom Membership Provider. They both are independent.
The built-in SqlMembership provider and SqlRoleProvider share aspnet_Users and aspnet_Application tables. With SqlRoleProvider, whenever you add a user to a Role, it will check aspnet_Users table if a user exist (it will check username+applicaitonID combination). If a user does not exists it will create one for you. If a user exists(this can be the case when user was created using SqlMembershipProvider) it will just add user to a role and not create a user.
So again, yes it should work.
I have never tried this but based on my experience with SqlMembershipProvider and SqlRoleProvider, I would say this is possible. However I believe the SqlRoleProvider is going to require that you store (or at least mirror) your membership database into the schema setup by the Aspnet_regsql.exe tool, since it will need those tables for methods such as RoleProvider.FindUsersInRole
that return a list of users.
For information on implementing a custom membership provider, see this article:
MSDN: Implementing a Membership Provider
Edit: The more I look at this the more it looks like the only level of interaction between SqlMembershipProvider and SqlRoleProvider are at the SQL DB level, so again as long as you implement your custom MembershipProvider to store (or mirror) your user data in SQL the same way SqlMembershipProvider does, you should be golden.
精彩评论