Ejemplo n.º 1
0
        public UsingHttpModulesSection()
        {
            // <Snippet1>

// Get the Web application configuration.
            Configuration configuration = WebConfigurationManager.OpenWebConfiguration("/aspnetTest");

// Get the HttpModulesSection.
            HttpModulesSection httpModulesSection = (HttpModulesSection)configuration.GetSection("system.web/httpModules");

// </Snippet1>

// <Snippet2>

// Create a new HttpModulesSection object.
            HttpModulesSection newHttpModulesSection = new HttpModulesSection();

// </Snippet2>

// <Snippet3>

// Get the modules collection.
            HttpModuleActionCollection httpModules = httpModulesSection.Modules;

// Read the modules information.
            StringBuilder modulesInfo = new StringBuilder();

            for (int i = 0; i < httpModules.Count; i++)
            {
                modulesInfo.Append(
                    string.Format("Name: {0}\nType: {1}\n\n", httpModules[i].Name,
                                  httpModules[i].Type));
            }
// </Snippet3>
        }
Ejemplo n.º 2
0
        /// <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));
                }
            }
        }
Ejemplo n.º 3
0
        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;
            }
        }
Ejemplo n.º 4
0
        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");

            // </Snippet1>


            // <Snippet2>
            // Create a new section object.
            HttpModuleAction newModuleAction =
                new HttpModuleAction("MyModule",
                                     "MyModuleType");

            // </Snippet2>


            // <Snippet3>

            // Initialize the module name and type properties.
            newModuleAction.Name = "ModuleName";
            newModuleAction.Type = "ModuleType";

            // </Snippet3>

            // <Snippet4>

            // Get the modules collection.
            HttpModuleActionCollection httpModules =
                httpModulesSection.Modules;
            string moduleFound = "moduleName not found.";

            // Find the module with the specified name.
            foreach (HttpModuleAction currentModule in httpModules)
            {
                if (currentModule.Name == "moduleName")
                {
                    moduleFound = "moduleName found.";
                }
            }
            // </Snippet4>



            // <Snippet5>

            // Get the modules collection.
            HttpModuleActionCollection httpModules2 =
                httpModulesSection.Modules;
            string typeFound = "typeName not found.";

            // Find the module with the specified type.
            foreach (HttpModuleAction currentModule in httpModules2)
            {
                if (currentModule.Type == "typeName")
                {
                    typeFound = "typeName found.";
                }
            }

            // </Snippet5>
        }
Ejemplo n.º 5
0
        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>
        }