|
-
Sep 27th, 2010, 08:19 AM
#1
Thread Starter
PowerPoster
Custom Role Provider and Membership Provider
Hi Guys,
I have watched the how to video on Creating a Custom Membership provider. So far it works great. My login control interacts well with it etc.
Now i've created a Custom Role Provider. I've created a class that inherits the RoleProvider base class and i've added code to each Sub.
My question is, what is the best way to implement the role provider, considering I get the Roles etc from the database?
Please help
-
Sep 27th, 2010, 09:51 AM
#2
Re: Custom Role Provider and Membership Provider
Hmmm...
I am confused?!?
What exactly are you asking? Are you asking how to store the roles in your custom database?
Gary
-
Sep 28th, 2010, 03:59 AM
#3
Thread Starter
PowerPoster
Re: Custom Role Provider and Membership Provider
Hi Gary,
I know the membership provider interacts with the login, change password controls etc.
But i'm not sure where the Role Provider fits in and when it gets used. I can't seem to find any How To videos regarding Role Providers
-
Sep 28th, 2010, 07:08 AM
#4
Re: Custom Role Provider and Membership Provider
Hey,
The implementation is exactly the same as for the Membership Provider. You inherit from the base class, provide the implementation for the necessary methods, and away you go.
You can see the Role Provider in action in the Restricted Menu link in my signature.
As for getting started, have a look at the documentation here:
http://msdn.microsoft.com/en-us/library/8fw7xh74.aspx
Gary
-
Sep 28th, 2010, 07:21 AM
#5
Thread Starter
PowerPoster
Re: Custom Role Provider and Membership Provider
thanks gary,
i've done the custom provider class already. I can pots it if you want to have a look
What I want is to be able to assign roles to users on an admin page for example. is this possible?
Then I want to enable/disable menu options based on the logged in users role.
Does the roles stuff have to be specified in the web config? I want to read that info from my database.
I've created a roles table and a user_in_roles table
-
Sep 28th, 2010, 08:44 AM
#6
Re: Custom Role Provider and Membership Provider
Hello,
To be clear, there are three providers that you can create custom versions of them.
Membership
Roles
Profile
From what you have described, you have done the first provider, the membership one, but you haven't done either the Roles one, of the Profile one.
Gary
-
Sep 28th, 2010, 08:50 AM
#7
Thread Starter
PowerPoster
Re: Custom Role Provider and Membership Provider
Hi gary,
I've done the membership provider as well as the role provider. but i'm not sure how to implement the role provider as that I can assign roles to users from my users table as opposed to setting the roles stuff in the web.config file
-
Sep 28th, 2010, 09:22 AM
#8
Re: Custom Role Provider and Membership Provider
Hey,
Ah, ok, I see what you are getting at now.
Have you edited your web.config file to indicate that you want to use your providers? If you have, then open up the ASP.Net Web Site Config Tool, under either the Project or Website menu, and then ASP.Net Wed Site Tool (or something like that).
That should let you both create users, and assign roles etc.
Gary
-
Sep 29th, 2010, 12:59 AM
#9
Thread Starter
PowerPoster
Re: Custom Role Provider and Membership Provider
thanks Gary. I have edited the web.config file. however I want to assign roles programmatically and not using the tool. is it possible?
-
Sep 29th, 2010, 01:08 AM
#10
Re: Custom Role Provider and Membership Provider
Yes, it is certainly possible, however, there is no built in way to do it. You are going to need to program the ability using code. In order to add a user to a particular role, or a set of roles, you can calll the AddUsersToRoles method:
http://msdn.microsoft.com/en-us/libr...rstoroles.aspx
Which you should have implemented in your Role Provider.
Gary
-
Sep 29th, 2010, 01:28 AM
#11
Thread Starter
PowerPoster
Re: Custom Role Provider and Membership Provider
thanks Gary
So of I create a gridview for example with each user in 1 column and the roles in a dropdown list in another column. I can then create an instance of my class and then save the info right
-
Sep 29th, 2010, 01:49 AM
#12
Re: Custom Role Provider and Membership Provider
Hey,
I am not sure exactly what you mean by an instance of your class. Can you confirm what you mean?
In theory, you should be able to call it like this:
Code:
Roles.AddUsersToRoles(newusers, rolesList)
Where newusers is an array of string with the names of the users, and rolesList an array of strings containing the names of the roles you want to add them to.
Gary
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|