public RoleService()
        {
            //HACK: Hardcoded values!!!
            NameValueCollection config = new NameValueCollection();

            config.Add("connectionStringName", "arachnode_net_ConnectionString");
            config.Add("applicationName", "arachnode.net");

            SqlRoleProvider.Initialize("SqlRoleProvider", config);
        }
Пример #2
0
        public AspNetAuthorizationService(string connectionStringName, string appName)
        {
            if (Roles.Providers.Count == 0)
            {
                //lock it off to avoid collisions
                lock (_lock) {
                    SqlRoleProvider provider = new SqlRoleProvider();

                    //The settings
                    NameValueCollection settings = new NameValueCollection();
                    settings.Add("connectionStringName", connectionStringName);

                    //initialize it
                    provider.Initialize(appName, settings);

                    Roles.Providers.Add(provider);
                }
            }
        }
Пример #3
0
        private static RoleProvider CreateRoleProvider()
        {
            var config = ConfigurationManager.OpenExeConfiguration(assemblyFilePath);

            var systemWebGroup = config.SectionGroups["system.web"];

            if (systemWebGroup == null)
            {
                throw new ConfigurationErrorsException("system.web group not found in configuration");
            }

            var roleManagerSection = systemWebGroup.Sections["roleManager"];

            if (roleManagerSection == null)
            {
                throw new ConfigurationErrorsException("roleManager section not found in system.web group");
            }

            var defaultProviderProperty = roleManagerSection.ElementInformation.Properties["defaultProvider"];

            if (defaultProviderProperty == null)
            {
                throw new ConfigurationErrorsException("defaultProvider property not found in roleManager section");
            }

            var defaultProviderName = defaultProviderProperty.Value as string;

            if (defaultProviderName == null)
            {
                throw new ConfigurationErrorsException("defaultProvider property is not a string value");
            }

            var providersProperty = roleManagerSection.ElementInformation.Properties["providers"];

            if (providersProperty == null)
            {
                throw new ConfigurationErrorsException("providers property not found in roleManagerSection section");
            }

            var providerCollection = providersProperty.Value as ProviderSettingsCollection;

            if (providerCollection == null)
            {
                throw new ConfigurationErrorsException("providers property is not an instance of ProviderSettingsCollection");
            }

            ProviderSettings roleProviderSettings = null;

            foreach (ProviderSettings providerSetting in providerCollection)
            {
                if (providerSetting.Name == defaultProviderName)
                {
                    roleProviderSettings = providerSetting;
                }
            }

            if (roleProviderSettings == null)
            {
                if (providerCollection.Count > 0)
                {
                    roleProviderSettings = providerCollection[0];
                }
                else
                {
                    throw new ConfigurationErrorsException("No providers found in configuration");
                }
            }

            var provider = new SqlRoleProvider();

            provider.Initialize("MySqlRoleManager", roleProviderSettings.Parameters);
            return(provider);
        }