public void Add_ProviderBase ()
		{
			TestProviderBase pb = new TestProviderBase ();
			MembershipProviderCollection mpc = new MembershipProviderCollection ();
			mpc.Add (pb);
			// Add accept ProviderBase but docs says it throws 
			// an exception if it's not a MembershipProvider
		}
Beispiel #2
0
        private static bool InitializeSettings(bool initializeGeneralSettings, RuntimeConfig appConfig, MembershipSection settings)
        {
            if (!initializeGeneralSettings)
            {
                return(false);
            }

            s_HashAlgorithmType       = settings.HashAlgorithmType;
            s_HashAlgorithmFromConfig = !string.IsNullOrEmpty(s_HashAlgorithmType);
            if (!s_HashAlgorithmFromConfig)
            {
                // If no hash algorithm is specified, use the same as the "validation" in "<machineKey>".
                // If the validation is "3DES", switch it to use "SHA1" instead.
                MachineKeyValidation v = appConfig.MachineKey.Validation;
                if (v != MachineKeyValidation.AES && v != MachineKeyValidation.TripleDES)
                {
                    s_HashAlgorithmType = appConfig.MachineKey.ValidationAlgorithm;
                }
                else
                {
                    s_HashAlgorithmType = "SHA1";
                }
            }
            s_Providers = new MembershipProviderCollection();
            if (HostingEnvironment.IsHosted)
            {
                ProvidersHelper.InstantiateProviders(settings.Providers, s_Providers, typeof(MembershipProvider));
            }
            else
            {
                foreach (ProviderSettings ps in settings.Providers)
                {
                    Type t = Type.GetType(ps.Type, true, true);
                    if (!typeof(MembershipProvider).IsAssignableFrom(t))
                    {
                        throw new ArgumentException(SR.GetString(SR.Provider_must_implement_type, typeof(MembershipProvider).ToString()));
                    }
                    MembershipProvider  provider    = (MembershipProvider)Activator.CreateInstance(t);
                    NameValueCollection pars        = ps.Parameters;
                    NameValueCollection cloneParams = new NameValueCollection(pars.Count, StringComparer.Ordinal);
                    foreach (string key in pars)
                    {
                        cloneParams[key] = pars[key];
                    }
                    provider.Initialize(ps.Name, cloneParams);
                    s_Providers.Add(provider);
                }
            }

            TimeSpan timeWindow = settings.UserIsOnlineTimeWindow;

            s_UserIsOnlineTimeWindow = (int)timeWindow.TotalMinutes;

            return(true);
        }
Beispiel #3
0
 private static bool InitializeSettings(bool initializeGeneralSettings, RuntimeConfig appConfig, MembershipSection settings)
 {
     if (!initializeGeneralSettings)
     {
         return(false);
     }
     s_HashAlgorithmType       = settings.HashAlgorithmType;
     s_HashAlgorithmFromConfig = !string.IsNullOrEmpty(s_HashAlgorithmType);
     if (!s_HashAlgorithmFromConfig)
     {
         MachineKeyValidation validation = appConfig.MachineKey.Validation;
         if ((validation != MachineKeyValidation.AES) && (validation != MachineKeyValidation.TripleDES))
         {
             s_HashAlgorithmType = appConfig.MachineKey.ValidationAlgorithm;
         }
         else
         {
             s_HashAlgorithmType = "SHA1";
         }
     }
     s_Providers = new MembershipProviderCollection();
     if (HostingEnvironment.IsHosted)
     {
         ProvidersHelper.InstantiateProviders(settings.Providers, s_Providers, typeof(MembershipProvider));
     }
     else
     {
         foreach (ProviderSettings settings2 in settings.Providers)
         {
             Type c = Type.GetType(settings2.Type, true, true);
             if (!typeof(MembershipProvider).IsAssignableFrom(c))
             {
                 throw new ArgumentException(System.Web.SR.GetString("Provider_must_implement_type", new object[] { typeof(MembershipProvider).ToString() }));
             }
             MembershipProvider  provider   = (MembershipProvider)Activator.CreateInstance(c);
             NameValueCollection parameters = settings2.Parameters;
             NameValueCollection config     = new NameValueCollection(parameters.Count, StringComparer.Ordinal);
             foreach (string str in parameters)
             {
                 config[str] = parameters[str];
             }
             provider.Initialize(settings2.Name, config);
             s_Providers.Add(provider);
         }
     }
     s_UserIsOnlineTimeWindow = (int)settings.UserIsOnlineTimeWindow.TotalMinutes;
     return(true);
 }
		public void Add_Null ()
		{
			MembershipProviderCollection mpc = new MembershipProviderCollection ();
			mpc.Add (null);
		}
        public void InjectMembershipImplementation(IEnumerable<KeyValuePair<string, string>> simulatedAppConfigSettings)
        {
            if (MembershipIsInitialized)
                _originalProvider = MembershipProvider;
            else
                _originalProvider = null;

            _injectedProvider = GetProvider();

            InitializeMembershipProviderFromConfigEntry(_injectedProvider, simulatedAppConfigSettings);

            PostInitializeUpdate(_injectedProvider);

            MembershipProvider = _injectedProvider;
            MembershipIsInitialized = true;

            MembershipProviders = new MembershipProviderCollection();
            MembershipProviders.Add(_injectedProvider);
            MembershipProviders.SetReadOnly();
        }
 private static bool InitializeSettings(bool initializeGeneralSettings, RuntimeConfig appConfig, MembershipSection settings)
 {
     if (!initializeGeneralSettings)
     {
         return false;
     }
     s_HashAlgorithmType = settings.HashAlgorithmType;
     s_HashAlgorithmFromConfig = !string.IsNullOrEmpty(s_HashAlgorithmType);
     if (!s_HashAlgorithmFromConfig)
     {
         MachineKeyValidation validation = appConfig.MachineKey.Validation;
         if ((validation != MachineKeyValidation.AES) && (validation != MachineKeyValidation.TripleDES))
         {
             s_HashAlgorithmType = appConfig.MachineKey.ValidationAlgorithm;
         }
         else
         {
             s_HashAlgorithmType = "SHA1";
         }
     }
     s_Providers = new MembershipProviderCollection();
     if (HostingEnvironment.IsHosted)
     {
         ProvidersHelper.InstantiateProviders(settings.Providers, s_Providers, typeof(MembershipProvider));
     }
     else
     {
         foreach (ProviderSettings settings2 in settings.Providers)
         {
             Type c = Type.GetType(settings2.Type, true, true);
             if (!typeof(MembershipProvider).IsAssignableFrom(c))
             {
                 throw new ArgumentException(System.Web.SR.GetString("Provider_must_implement_type", new object[] { typeof(MembershipProvider).ToString() }));
             }
             MembershipProvider provider = (MembershipProvider) Activator.CreateInstance(c);
             NameValueCollection parameters = settings2.Parameters;
             NameValueCollection config = new NameValueCollection(parameters.Count, StringComparer.Ordinal);
             foreach (string str in parameters)
             {
                 config[str] = parameters[str];
             }
             provider.Initialize(settings2.Name, config);
             s_Providers.Add(provider);
         }
     }
     s_UserIsOnlineTimeWindow = (int) settings.UserIsOnlineTimeWindow.TotalMinutes;
     return true;
 }
        private static bool InitializeSettings(bool initializeGeneralSettings, RuntimeConfig appConfig, MembershipSection settings) {
            if (!initializeGeneralSettings) {
                return false;
            }

            s_HashAlgorithmType = settings.HashAlgorithmType;
            s_HashAlgorithmFromConfig = !string.IsNullOrEmpty(s_HashAlgorithmType);
            if (!s_HashAlgorithmFromConfig) {
                // If no hash algorithm is specified, use the same as the "validation" in "<machineKey>".
                // If the validation is "3DES", switch it to use "SHA1" instead.
                MachineKeyValidation v = appConfig.MachineKey.Validation;
                if (v != MachineKeyValidation.AES && v != MachineKeyValidation.TripleDES)
                    s_HashAlgorithmType = appConfig.MachineKey.ValidationAlgorithm;
                else
                    s_HashAlgorithmType = "SHA1";
            }
            s_Providers = new MembershipProviderCollection();
            if (HostingEnvironment.IsHosted) {
                ProvidersHelper.InstantiateProviders(settings.Providers, s_Providers, typeof(MembershipProvider));
            } else {
                foreach (ProviderSettings ps in settings.Providers) {
                    Type t = Type.GetType(ps.Type, true, true);
                    if (!typeof(MembershipProvider).IsAssignableFrom(t))
                        throw new ArgumentException(SR.GetString(SR.Provider_must_implement_type, typeof(MembershipProvider).ToString()));
                    MembershipProvider provider = (MembershipProvider)Activator.CreateInstance(t);
                    NameValueCollection pars = ps.Parameters;
                    NameValueCollection cloneParams = new NameValueCollection(pars.Count, StringComparer.Ordinal);
                    foreach (string key in pars)
                        cloneParams[key] = pars[key];
                    provider.Initialize(ps.Name, cloneParams);
                    s_Providers.Add(provider);
                }
            }

            TimeSpan timeWindow = settings.UserIsOnlineTimeWindow;
            s_UserIsOnlineTimeWindow = (int)timeWindow.TotalMinutes;

            return true;
        }