/// <summary> /// Adds an httpModule to the system.web section to point to our domain service module /// </summary> /// <param name="domainServiceModuleTypeName">Full type name to the domain service module</param> public void AddHttpModule(string domainServiceModuleTypeName) { Debug.Assert(!string.IsNullOrEmpty(domainServiceModuleTypeName), "domainServiceModuleTypeName cannot be empty"); if (!string.IsNullOrEmpty(domainServiceModuleTypeName)) { System.Web.Configuration.HttpModulesSection httpModulesSection = (System.Web.Configuration.HttpModulesSection) this._configuration.GetSection("system.web/httpModules"); if (httpModulesSection != null) { HttpModuleActionCollection modules = httpModulesSection.Modules; modules.Add(new HttpModuleAction(BusinessLogicClassConstants.DomainServiceModuleName, domainServiceModuleTypeName)); } } }
public static void Run() { if (!_hasInited) { DetermineWhatFilesAndAssembliesToScan(); bool isRunningMono = Type.GetType("Mono.Runtime") != null; if (isRunningMono) { RunPreStartMethods(designerMode: false); } else { // In CBM mode, pass true so that only the methods that have RunInDesigner=true get called RunPreStartMethods(designerMode: IsInClientBuildManager()); } // Register our module to handle any Post Start methods. But outside of ASP.NET, just run them now if (HostingEnvironment.IsHosted) { Type startMethodType = typeof(StartMethodCallingModule); if (isRunningMono) { HttpModuleActionCollection modules = (WebConfigurationManager.GetWebApplicationSection("system.web/httpModules") as HttpModulesSection).Modules; modules.Add(new HttpModuleAction(startMethodType.FullName, startMethodType.AssemblyQualifiedName)); } else { Microsoft.Web.Infrastructure.DynamicModuleHelper.DynamicModuleUtility.RegisterModule(startMethodType); } } else { RunPostStartMethods(); } _hasInited = true; } }
public static void Main() { // <Snippet1> // Get the Web application configuration. System.Configuration.Configuration configuration = WebConfigurationManager.OpenWebConfiguration( "/aspnetTest"); // Get the section. HttpModulesSection httpModulesSection = (HttpModulesSection)configuration.GetSection( "system.web/httpModules"); // Get the collection. HttpModuleActionCollection modulesCollection = httpModulesSection.Modules; // </Snippet1> // <Snippet2> // Create a new HttpModuleActionCollection object. HttpModuleActionCollection newModuleActionCollection = new HttpModuleActionCollection(); // </Snippet2> //<Snippet3> // Create a new module object. HttpModuleAction ModuleAction = new HttpModuleAction("MyModuleName", "MyModuleType"); // Add the module to the collection. if (!httpModulesSection.SectionInformation.IsLocked) { modulesCollection.Add(ModuleAction); configuration.Save(); } //</Snippet3> //<Snippet4> // Set the module object. HttpModuleAction ModuleAction1 = new HttpModuleAction("MyModule1Name", "MyModule1Type"); // Get the module collection index. int moduleIndex = modulesCollection.IndexOf(ModuleAction1); //</Snippet4> //<Snippet5> // Set the module object. HttpModuleAction ModuleAction2 = new HttpModuleAction("MyModule2Name", "MyModule2Type"); // Remove the module from the collection. if (!httpModulesSection.SectionInformation.IsLocked) { modulesCollection.Remove(ModuleAction2); configuration.Save(); } //</Snippet5> //<Snippet6> // Remove the module from the collection. if (!httpModulesSection.SectionInformation.IsLocked) { modulesCollection.Remove("TimerModule"); configuration.Save(); } //</Snippet6> //<Snippet7> // Remove the module from the collection. if (!httpModulesSection.SectionInformation.IsLocked) { modulesCollection.RemoveAt(0); configuration.Save(); } //</Snippet7> //<Snippet8> // Clear the collection. if (!httpModulesSection.SectionInformation.IsLocked) { modulesCollection.Clear(); configuration.Save(); } //</Snippet8> }