0
votes

I'm trying to implement a custom membership provider for Sitefinity. So far the actual membership stuff (authentication, listing the users etc) works fine. What I'd like to do is set permissions within the site for anyone logging in on that provider. For example, lets say the custom provider is called CustomerDBMembershipProvider and lets assume it grabs records from some kind of separate repository of usernames and passwords.

I want anyone who logs in using the CustomerDBMembershipProvider to have access to view a customer-only page on the site. How can I restrict that page so it can only be seen by people who have logged in using the CustomerDBMembershipProvider?

1

1 Answers

0
votes

First of all I hope I understood your problem right. I can think two options here

Option 1

  1. Create a custom role provider, implement GetAllRoles,RoleExists, IsUserInRole,GetRolesForUser. Rest all you can keep, empty method with throw new NotSupportedException(); In this role provider you have get list of roles for each user, from your custom user source. If you don't have custom roles database, then you can hardcode to have one fixed role for this role provider.

  2. Integrate this custom role provider with sitefinity, in web.config.

  3. Now you should see the additional roles in the page permission manager. You can now provide access to only this role for the restricted pages.

Option 2.

  1. Create a new role in sitefinity
  2. Assign users for the roles. Here in the providers dropdown select, your provider CustomerDBMembershipProvider. Assign all the users to this role.
  3. Change the permission of the required page to allow only for this new role.

With this approach, whenever a new user is added to your custom source, you need to map them to the new role, created in sitefinity. If you are ok to change your membership provider, then in the ValidateUser function, after user is validated, you can add the newly created sitefinity role to the user. Then you don't need to manually map the role in sitefinitiy, every time a new user is created.