Results 1 to 12 of 12

Thread: Custom Role Provider and Membership Provider

  1. #1

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    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

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

  3. #3

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    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

  4. #4
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

  5. #5

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    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

  6. #6
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

  7. #7

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    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

  8. #8
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

  9. #9

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    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?

  10. #10
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

  11. #11

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    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

  12. #12
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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
  •  



Click Here to Expand Forum to Full Width