private static void Validate(object value) { if (value == null) { throw new ArgumentNullException("httpModule"); } HttpModuleAction elem = (HttpModuleAction)value; if (HttpModuleAction.IsSpecialModule(elem.Type)) { throw new ConfigurationErrorsException( SR.GetString(SR.Special_module_cannot_be_added_manually, elem.Type), elem.ElementInformation.Properties["type"].Source, elem.ElementInformation.Properties["type"].LineNumber); } if (HttpModuleAction.IsSpecialModuleName(elem.Name)) { throw new ConfigurationErrorsException( SR.GetString(SR.Special_module_cannot_be_added_manually, elem.Name), elem.ElementInformation.Properties["name"].Source, elem.ElementInformation.Properties["name"].LineNumber); } }
// https://msdn.microsoft.com/en-us/library/tkwek5a4%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396 // Example Configuration Code for an HTTP Module: public static void AddModule(Configuration config, string moduleName, string moduleClass) { HttpModulesSection section = (HttpModulesSection)config.GetSection("system.web/httpModules"); // Create a new module action object. HttpModuleAction moduleAction = new HttpModuleAction( moduleName, moduleClass); // "RequestTimeIntervalModule", "Samples.Aspnet.HttpModuleExamples.RequestTimeIntervalModule"); // Look for an existing configuration for this module. int indexOfModule = section.Modules.IndexOf(moduleAction); if (-1 != indexOfModule) { // Console.WriteLine("RequestTimeIntervalModule module is already configured at index {0}", indexOfModule); } else { section.Modules.Add(moduleAction); if (!section.SectionInformation.IsLocked) { config.Save(); // Console.WriteLine("RequestTimeIntervalModule module configured."); } } }
protected override bool IsElementRemovable(ConfigurationElement element) { HttpModuleAction action = (HttpModuleAction)element; if (base.BaseIndexOf(action) != -1) { return(true); } if (HttpModuleAction.IsSpecialModuleName(action.Name)) { throw new ConfigurationErrorsException(System.Web.SR.GetString("Special_module_cannot_be_removed_manually", new object[] { action.Name }), action.FileName, action.LineNumber); } throw new ConfigurationErrorsException(System.Web.SR.GetString("Module_not_in_app", new object[] { action.Name }), action.FileName, action.LineNumber); }
private static void Validate(object value) { if (value == null) { throw new ArgumentNullException("httpModule"); } HttpModuleAction action = (HttpModuleAction)value; if (IsSpecialModule(action.Type)) { throw new ConfigurationErrorsException(System.Web.SR.GetString("Special_module_cannot_be_added_manually", new object[] { action.Type }), action.ElementInformation.Properties["type"].Source, action.ElementInformation.Properties["type"].LineNumber); } if (IsSpecialModuleName(action.Name)) { throw new ConfigurationErrorsException(System.Web.SR.GetString("Special_module_cannot_be_added_manually", new object[] { action.Name }), action.ElementInformation.Properties["name"].Source, action.ElementInformation.Properties["name"].LineNumber); } }
private static void AddWebModules(System.Configuration.Configuration config, string name, string type) { // Get the <httpModules> section. HttpModulesSection sectionSystemWeb = (HttpModulesSection)config.GetSection("system.web/httpModules"); // Create a new module action object. HttpModuleAction myHttpModuleAction = new HttpModuleAction(name, type); int indexOfHttpModule = sectionSystemWeb.Modules.IndexOf(myHttpModuleAction); if (indexOfHttpModule == -1) { sectionSystemWeb.Modules.Add(myHttpModuleAction); if (!sectionSystemWeb.SectionInformation.IsLocked) { config.Save(); } } }
protected override bool IsElementRemovable(ConfigurationElement element) { HttpModuleAction module = (HttpModuleAction)element; if (BaseIndexOf(module) == -1) // does it exist? { if (HttpModuleAction.IsSpecialModuleName(module.Name)) { throw new ConfigurationErrorsException(SR.GetString(SR.Special_module_cannot_be_removed_manually, module.Name), module.FileName, module.LineNumber); } else { throw new ConfigurationErrorsException(SR.GetString(SR.Module_not_in_app, module.Name), module.FileName, module.LineNumber); } } return(true); }
public int IndexOf(HttpModuleAction action) { return(BaseIndexOf(action)); }
// instantiates modules that have been added to the dynamic registry (classic pipeline) private HttpModuleCollection CreateDynamicModules() { HttpModuleCollection moduleCollection = new HttpModuleCollection(); foreach (DynamicModuleRegistryEntry entry in _dynamicModuleRegistry.LockAndFetchList()) { HttpModuleAction modAction = new HttpModuleAction(entry.Name, entry.Type); moduleCollection.AddModule(modAction.Entry.ModuleName, modAction.Entry.Create()); } return moduleCollection; }
public int IndexOf(HttpModuleAction action) { return(default(int)); }
public void Remove(HttpModuleAction action) { }
public int IndexOf(HttpModuleAction action) { return default(int); }
public void Add(HttpModuleAction httpModule) { }
public void Remove(HttpModuleAction action) { BaseRemove(action.Key); }
public void Add(HttpModuleAction httpModule) { BaseAdd(httpModule); }
public int IndexOf(HttpModuleAction action) { return BaseIndexOf(action); }
internal static void CheckConfiguration(ISite site) { if (site == null) { return; } IWebApplication app = (IWebApplication)site.GetService(typeof(IWebApplication)); if (app == null) { return; } Configuration config = app.OpenWebConfiguration(false); HttpHandlersSection handlers = (HttpHandlersSection)config.GetSection("system.web/httpHandlers"); // Does the httpHandlers Secton already exist? if (handlers == null) { // If not, add it... handlers = new HttpHandlersSection(); ConfigurationSectionGroup group = config.GetSectionGroup("system.web"); // Does the system.web Section already exist? if (group == null) { // If not, add it... config.SectionGroups.Add("system.web", new ConfigurationSectionGroup()); group = config.GetSectionGroup("system.web"); } if (group != null) { group.Sections.Add("httpHandlers", handlers); } } HttpHandlerAction action = new HttpHandlerAction("*/ext.axd", "Ext.Net.ResourceHandler", "*", false); // Does the ResourceHandler already exist? if (handlers.Handlers.IndexOf(action) < 0) { // If not, add it... handlers.Handlers.Add(action); config.Save(); } HttpModulesSection modules = (HttpModulesSection)config.GetSection("system.web/httpModules"); // Does the httpModules Secton already exist? if (modules == null) { // If not, add it... modules = new HttpModulesSection(); ConfigurationSectionGroup group = config.GetSectionGroup("system.web"); // Does the system.web Section already exist? if (group == null) { // If not, add it... config.SectionGroups.Add("system.web", new ConfigurationSectionGroup()); group = config.GetSectionGroup("system.web"); } if (group != null) { group.Sections.Add("httpModules", modules); } } //<add name="DirectRequestModule" type="Ext.Net.DirectRequestModule, Ext.Net" /> HttpModuleAction action2 = new HttpModuleAction("DirectRequestModule", "Ext.Net.DirectRequestModule, Ext.Net"); // Does the ResourceHandler already exist? if (modules.Modules.IndexOf(action2) < 0) { // If not, add it... modules.Modules.Add(action2); config.Save(); } }