public static void AddUIModuleProvider(string name, string type)
{
using (ServerManager mgr = new ServerManager())
{
// First register the Module Provider
Configuration adminConfig = mgr.GetAdministrationConfiguration();
ConfigurationSection moduleProvidersSection = adminConfig.GetSection("moduleProviders");
ConfigurationElementCollection moduleProviders = moduleProvidersSection.GetCollection();
if (FindByAttribute(moduleProviders, "name", name) == null)
{
ConfigurationElement moduleProvider = moduleProviders.CreateElement();
moduleProvider.SetAttributeValue("name", name);
moduleProvider.SetAttributeValue("type", type);
moduleProviders.Add(moduleProvider);
}
// Now register it so that all Sites have access to this module
ConfigurationSection modulesSection = adminConfig.GetSection("modules");
ConfigurationElementCollection modules = modulesSection.GetCollection();
if (FindByAttribute(modules, "name", name) == null)
{
ConfigurationElement module = modules.CreateElement();
module.SetAttributeValue("name", name);
modules.Add(module);
}
mgr.CommitChanges();
}
}