When you retrieve your own class from the MembershipProvider , you must override the Initialize() method, it has the following signature:
public override void Initialize(string name, NameValueCollection config);
System.Collections.NameValueCollection is a dictionary where you will find the parameters recorded in the web.config . These parameters are specified in the same way as you specify parameters for "standard" providers (as attributes). Each dictionary entry has an attribute name key and, as a value, an attribute value (like string ).
public class MyMembershipProvider : MembershipProvider { public override void Initialize(string name, NameValueCollection config) { base.Initialize(name, config); _enablePasswordReset = config.GetBoolean("enablePasswordReset", true); } }
Where, in my example, GetBoolean() is an extension method declared somewhere as follows:
public static bool GetBoolean(this NameValueCollection config, string valueName, bool? defaultValue) { object obj = config[valueName]; if (obj == null) { if (!defaultValue.HasValue) throw new WarningException("Required field has not been specified."); return defaultValue.Value; } bool value = defaultValue; if (obj is Boolean) return (bool)obj; IConvertible convertible = obj as IConvertible; try { return convertible.ToBoolean(CultureInfo.InvariantCulture); } catch (Exception) { if (!defaultValue.HasValue) throw new WarningException("Required field has invalid format."); return defaultValue.Value; } }
source share