public override void Initialize(string name, NameValueCollection config)
{
if (config == null)
{
throw new ArgumentNullException("config");
}
if (string.IsNullOrEmpty(name))
{
name = "XmlMembershipProvider";
}
if (string.IsNullOrEmpty(config["description"]))
{
config.Remove("description");
config.Add("description", "XML role provider");
}
base.Initialize(name, config);
// Initialize _XmlFileName and make sure the path
// is app-relative
var filename = config["xmlFileName"];
if (string.IsNullOrEmpty(filename))
{
filename = "roles.xml";
}
else
{
if (!VirtualPathUtility.IsAppRelative(filename))
{
throw new ArgumentException("xmlFileName must be app-relative");
}
}
this.xmlFileName = filename;
config.Remove("xmlFileName");
// Make sure we have permission to read the XML data source and
// throw an exception if we don't
var permission = new FileIOPermission(FileIOPermissionAccess.Write, this.XmlFullyQualifiedPath);
permission.Demand();
this.ReadMembershipDataStore();
if (!File.Exists(this.XmlFullyQualifiedPath))
{
this.AddUsersToRoles(this.userNames.ToArray(), this.defaultRolesToAdd);
}
// Now that we know a xml file exists we can call it.
this.ReadRoleDataStore();
// Throw an exception if unrecognized attributes remain
if (config.Count > 0)
{
var attr = config.GetKey(0);
if (!string.IsNullOrEmpty(attr))
{
throw new ProviderException(string.Format("Unrecognized attribute: {0}", attr));
}
}
}