मैंने सभी संबंधित प्रश्नों के माध्यम से पढ़ा है, लेकिन मैं अभी भी किसी कारण से सही समाधान प्राप्त करने में असमर्थ हूं, मेरे पक्ष में कुछ सही नहीं है, लेकिन यह सुनिश्चित नहीं है कि इसका क्या कारण है।मैं एक कस्टम सदस्यता प्रदाता पर आरंभ कैसे कॉल करूं?
public override void Initialize(string name, NameValueCollection config)
{
if (config == null)
{ throw new ArgumentNullException("config"); }
if (string.IsNullOrEmpty(name))
{ name = "MyMemberShipProvider"; }
if (string.IsNullOrEmpty(config["description"]))
{
config.Remove("description");
config.Add("description", "My Membership Provider");
}
base.Initialize(name, config);
_applicationName = GetConfigValue(config["applicationName"], System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath);
_maxInvalidPasswordAttempts = Convert.ToInt32(GetConfigValue(config["maxInvalidPasswordAttempts"], "5"));
_passwordAttemptWindow = Convert.ToInt32(GetConfigValue(config["passwordAttemptWindow"], "10"));
_minRequiredNonAlphaNumericCharacters = Convert.ToInt32(GetConfigValue(config["minRequiredAlphaNumericCharacters"], "1"));
_minRequiredPasswordLength = Convert.ToInt32(GetConfigValue(config["minRequiredPasswordLength"], "7"));
_passwordStregthRegularExpression = Convert.ToString(GetConfigValue(config["passwordStrengthRegularExpression"], String.Empty));
_enablePasswordReset = Convert.ToBoolean(GetConfigValue(config["enablePasswordReset"], "true"));
_enablePasswordRetrieval = Convert.ToBoolean(GetConfigValue(config["enablePasswordRetrieval"], "true"));
_requiredQuestionAndAnswer = Convert.ToBoolean(GetConfigValue(config["requiresQuestionAndAnswer"], "false"));
_requiredUniqueEmail = Convert.ToBoolean(GetConfigValue(config["requiresUniqueEmail"], "true"));
string temp_format = config["passwordFormat"];
if (temp_format == null)
{
temp_format = "Hashed";
}
switch (temp_format)
{
case "Hashed":
_passwordFormat = MembershipPasswordFormat.Hashed;
break;
case "Encrypted":
_passwordFormat = MembershipPasswordFormat.Encrypted;
break;
case "Clear":
_passwordFormat = MembershipPasswordFormat.Clear;
break;
default:
throw new ProviderException("Password format not supported.");
}
ConnectionStringSettings _connectionStringSettings = ConfigurationManager.ConnectionStrings[config["connectionStringName"]];
if (_connectionStringSettings == null || _connectionStringSettings.ConnectionString.Length == 0)
{
throw new ProviderException("Connection String Cannot Be Blank.");
}
_connectionString = _connectionStringSettings.ConnectionString;
//Get Encryption and Decryption Key Information From the Information.
System.Configuration.Configuration cfg = WebConfigurationManager.OpenWebConfiguration(System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath);
_machinekey = cfg.GetSection("system.web/machineKey") as MachineKeySection;
if (_machinekey.ValidationKey.Contains("AutoGenerate"))
{
if (PasswordFormat != MembershipPasswordFormat.Clear)
{
throw new ProviderException("Hashed or Encrypted passwords are not supported with auto-generated keys.");
}
}
}
और मैं को आरम्भ देखा है:
<membership defaultProvider="MyMemberShipProvider">
<providers>
<clear />
<add name="MyMemberShipProvider"
type="MyNameSpace.MyMemberShipProvider"
connectionStringName="ApplicationServices"
enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="false"
passwordFormat="Hashed"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="6"
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10"
passwordStrengthRegularExpression=""
applicationName="MyApplication" />
</providers>
</membership>
यहाँ मेरी प्रारंभ विधि के लिए कोड है:
मैं एक कस्टम सदस्यता प्रदाता बनाया है, यह भी करने के लिए अपने web.config बदल विधि को नहीं बुलाया गया था, मैंने यहां प्रश्नों के माध्यम से पढ़ा और लोग कह रहे थे कि मुझे मैन्युअल रूप से कॉल करने की ज़रूरत नहीं है, अगर मैंने अपना वेब.कॉन्फिग सही तरीके से तारित किया है, तो मुझे कुछ भी करने की ज़रूरत नहीं है, लेकिन मैंने कोशिश की मैन्युअल रूप से कॉल करें, लेकिन जब मैंने कोशिश की तो मुझे एक अमान्यकास्ट अपवाद दिया नाम ValueCollection डालने के लिए जी।
क्या कोई मेरी मदद कर सकता है? धन्यवाद
मैंने पहले से ही अपने प्रश्न पर प्रारंभिक कोड डाला है, और मैंने कीवर्ड को ओवरराइड किया है, और यह आग नहीं है, सुनिश्चित नहीं है कि क्यों। – PlayKid
आप सही हैं, यह स्थिर है, इस मामले में सिंगलटन नहीं, मैं अपनी पोस्ट संपादित करूंगा। धन्यवाद! –