当前位置: 首页>>代码示例>>C#>>正文


C# MembershipProvider.Initialize方法代码示例

本文整理汇总了C#中System.Web.Security.MembershipProvider.Initialize方法的典型用法代码示例。如果您正苦于以下问题:C# MembershipProvider.Initialize方法的具体用法?C# MembershipProvider.Initialize怎么用?C# MembershipProvider.Initialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.Security.MembershipProvider的用法示例。


在下文中一共展示了MembershipProvider.Initialize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetPasswordHelper

        private void GetPasswordHelper(bool requireQA, bool enablePasswordRetrieval, string answer)
        {
            MembershipCreateStatus status;
            provider = new MembershipProvider();
            NameValueCollection config = new NameValueCollection();
            config.Add("connectionStringName", _connStrName);
            config.Add("requiresQuestionAndAnswer", requireQA ? "true" : "false");
            config.Add("enablePasswordRetrieval", enablePasswordRetrieval ? "true" : "false");
            config.Add("passwordFormat", "clear");
            config.Add("applicationName", _applicationName);
            config.Add("writeExceptionsToEventLog", "false");
            provider.Initialize(null, config);

            provider.CreateUser("foo", "barbar!", "[email protected]", "color", "blue", true, null, out status);

            try
            {
                string password = provider.GetPassword("foo", answer);
                if (!enablePasswordRetrieval)
                    Assert.Fail("This should have thrown an exception");
                Assert.AreEqual("barbar!", password);
            }
            catch (MembershipPasswordException)
            {
                if (requireQA && answer != null)
                    Assert.Fail("This should not have thrown an exception");
            }
            catch (ProviderException)
            {
                if (requireQA && answer != null)
                    Assert.Fail("This should not have thrown an exception");
            }
        }
开发者ID:netdragoon,项目名称:MongoProviders,代码行数:33,代码来源:MembershipProviderTest.cs

示例2: InitializeMembershipProviderFromConfigEntry

        public void InitializeMembershipProviderFromConfigEntry(MembershipProvider result,
            IEnumerable<KeyValuePair<string, string>> simulatedAppConfigSettings)
        {
            NameValueCollection nameValueCollection = null;

            MembershipSection membership = ConfigurationManager.GetSection("system.web/membership") as MembershipSection;

            foreach (ProviderSettings settings in membership.Providers)
            {
                if (settings.Name == FixtureConstants.NameOfConfiguredMembershipProvider)
                {
                    nameValueCollection = new NameValueCollection(settings.Parameters);
                    break;
                }
            }

            if (nameValueCollection == null)
            {
                throw new Exception("Configuration not found for membership provider RavenDBMembership.");
            }

            nameValueCollection["connectionStringName"] = "StubConnectionString";

            foreach (var kvp in simulatedAppConfigSettings)
            {
                ValidateConfigurationValue(kvp.Key, kvp.Value);
                nameValueCollection.Set(kvp.Key, kvp.Value);
            }

            result.Initialize(FixtureConstants.NameOfConfiguredMembershipProvider, nameValueCollection);
        }
开发者ID:GrillerGeek,项目名称:RavenDBMembership,代码行数:31,代码来源:MembershipProviderOverride.cs


注:本文中的System.Web.Security.MembershipProvider.Initialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。