本文整理汇总了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");
}
}
示例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);
}