Quantcast
Channel: C1 CMS Foundation - Open Source on .NET
Viewing all articles
Browse latest Browse all 2540

New Post: Using my own membership and role provider

$
0
0
  1. You should be able to leave out the DataProviderPlugin if you just store the FormDefinitionFile in ~/App_Data/Composite/DynamicTypeForms
  2. In your form definition its more flexible to add the possible roles like this
<MultiKeySelector.Options>
   <ff:StaticMethodCall Type="System.Web.Security.Roles" Method="GetAllRoles" />
</MultiKeySelector.Options>
2a. Inject your roles with a roleprovider like this
    public class CompositeC1RoleProvider : RoleProvider
    {
        private static string[] _allRoles = new[] { "AUTHENTICATED", "ANONYMOUS" };

        private string _appName;

        public override string ApplicationName
        {
            get { return _appName; }
            set { _appName = value; }
        }

        public override void Initialize(string name, NameValueCollection config)
        {
            ApplicationName = config["applicationName"];
            if (String.IsNullOrEmpty(ApplicationName))
            {
                throw new ProviderException("Application name needs to be set");
            }

            base.Initialize(name, config);
        }

        public override void AddUsersToRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override void CreateRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            throw new NotImplementedException();
        }

        public override string[] FindUsersInRole(string roleName, string usernameToMatch)
        {
            return new string[0];
        }

        public override string[] GetAllRoles()
        {
            return _allRoles;
        }

        public override string[] GetRolesForUser(string username)
        {
            return new string[0];
        }

        public override string[] GetUsersInRole(string roleName)
        {
            return new string[0];
        }

        public override bool IsUserInRole(string username, string roleName)
        {
            return false;
        }

        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override bool RoleExists(string roleName)
        {
            return _allRoles.Contains(roleName);
        }
    }
2b. Register the roleprovider in web,config
<roleManager enabled="true" defaultProvider="CompositeC1">
      <providers>
        <clear />

        <add name="CompositeC1" type="YourNamespace.CompositeC1RoleProvider, YourAssembly"  applicationName="YourApplication" />
      </providers>
    </roleManager>

Viewing all articles
Browse latest Browse all 2540

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>