/// <summary>
		/// 获取HttpModulesSection
		/// </summary>
		/// <returns></returns>
		public static HttpModulesSection GetHttpModulesSection()
		{
			HttpModulesSection section = (HttpModulesSection)ConfigurationBroker.GetSection("deluxe.web/httpModules");

			if (section == null)
				section = new HttpModulesSection();

			return section;
		}
 /// <summary>
 /// Determines whether we need to add an httpModule to system.web for our domain service module
 /// </summary>
 /// <returns><c>true</c> means we need to modify the configuration to add an httpModule</returns>
 public bool DoWeNeedToAddHttpModule()
 {
     System.Web.Configuration.HttpModulesSection httpModulesSection = (System.Web.Configuration.HttpModulesSection) this._configuration.GetSection("system.web/httpModules");
     if (httpModulesSection != null)
     {
         return(!httpModulesSection.Modules.OfType <HttpModuleAction>()
                .Any(a => String.Equals(a.Name, BusinessLogicClassConstants.DomainServiceModuleName, StringComparison.OrdinalIgnoreCase)));
     }
     return(true);
 }
Exemplo n.º 3
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));
                }
            }
        }
Exemplo n.º 4
0
        public void WebConfigUtil_UpdateConfiguration()
        {
            string tempConfigFile = Path.GetTempFileName();

            try
            {
                File.WriteAllText(tempConfigFile, EmptyConfig);
                System.Configuration.Configuration cfg = ConfigurationManager.OpenExeConfiguration(tempConfigFile);
                WebConfigUtil webConfigUtil            = new WebConfigUtil(cfg);

                // Verify that none of the sections we wat to set are present
                Assert.IsFalse(webConfigUtil.IsAspNetCompatibilityEnabled(), "Blank config should not have AspNetCompatibility");
                Assert.IsFalse(webConfigUtil.IsMultipleSiteBindingsEnabled(), "Blank config should not have MultiSiteBinding");
                Assert.IsFalse(webConfigUtil.IsEndpointDeclared(BusinessLogicClassConstants.ODataEndpointName), "Blank config should not have OData endpoint");
                Assert.IsTrue(webConfigUtil.DoWeNeedToValidateIntegratedModeToWebServer(), "Blank config should not have validate integrated mode");
                Assert.IsTrue(webConfigUtil.DoWeNeedToAddHttpModule(), "Blank config should not have http module");
                Assert.IsTrue(webConfigUtil.DoWeNeedToAddModuleToWebServer(), "Blank config should not have http module to web server");

                string domainServiceFactoryName = WebConfigUtil.GetDomainServiceModuleTypeName();
                Assert.IsFalse(string.IsNullOrEmpty(domainServiceFactoryName), "Could not find domain service factory name");

                // ------------------------------------
                // Set everything we set from the wizard
                // ------------------------------------
                webConfigUtil.SetAspNetCompatibilityEnabled(true);
                webConfigUtil.SetMultipleSiteBindingsEnabled(true);
                webConfigUtil.AddValidateIntegratedModeToWebServer();
                webConfigUtil.AddHttpModule(domainServiceFactoryName);
                webConfigUtil.AddModuleToWebServer(domainServiceFactoryName);

                // ------------------------------------
                // Verify API's see the changes
                // ------------------------------------
                Assert.IsTrue(webConfigUtil.IsAspNetCompatibilityEnabled(), "Failed to set AspNetCompatibility");
                Assert.IsTrue(webConfigUtil.IsMultipleSiteBindingsEnabled(), "Failed to set MultiSiteBinding");
                Assert.IsFalse(webConfigUtil.DoWeNeedToValidateIntegratedModeToWebServer(), "Failed to set validate integrated mode");
                Assert.IsFalse(webConfigUtil.DoWeNeedToAddHttpModule(), "Failed to set http module");
                Assert.IsFalse(webConfigUtil.DoWeNeedToAddModuleToWebServer(), "Failed to set http module to web server");

                // ------------------------------------
                // Independently verify those changes
                // ------------------------------------
                // AspNetCompat
                ServiceHostingEnvironmentSection section = cfg.GetSection("system.serviceModel/serviceHostingEnvironment") as ServiceHostingEnvironmentSection;
                Assert.IsTrue(section != null && section.AspNetCompatibilityEnabled, "AspNetCompat did not set correct section");

                // MultisiteBindings
                Assert.IsTrue(section != null && section.MultipleSiteBindingsEnabled, "MultisiteBinding did not set correct section");

                // Http modules
                System.Web.Configuration.HttpModulesSection httpModulesSection = cfg.GetSection("system.web/httpModules") as System.Web.Configuration.HttpModulesSection;
                HttpModuleAction module = (httpModulesSection == null)
                                            ? null
                                            : httpModulesSection.Modules.OfType <HttpModuleAction>()
                                          .FirstOrDefault(a => String.Equals(a.Name, BusinessLogicClassConstants.DomainServiceModuleName, StringComparison.OrdinalIgnoreCase));
                Assert.IsNotNull(module, "Did not find httpModule");

                // ------------------------------------
                // Set and verify OData endpoint
                // ------------------------------------
                webConfigUtil.AddEndpointDeclaration(BusinessLogicClassConstants.ODataEndpointName, WebConfigUtil.GetODataEndpointFactoryTypeName());
                Assert.IsTrue(webConfigUtil.IsEndpointDeclared(BusinessLogicClassConstants.ODataEndpointName), "Failed to set OData endpoint");

                DomainServicesSection domainServicesSection = cfg.GetSection("system.serviceModel/domainServices") as DomainServicesSection;
                Assert.IsNotNull(domainServicesSection, "system.serviceModel/domainServices section not found");
                Assert.AreEqual(ConfigurationAllowDefinition.MachineToApplication, domainServicesSection.SectionInformation.AllowDefinition, "AllowDefinition s/b MachineToApplication");
                Assert.IsFalse(domainServicesSection.SectionInformation.RequirePermission, "RequirePermission s/b false");

                ProviderSettings setting = (domainServicesSection == null)
                                            ? null
                                            : domainServicesSection.Endpoints.OfType <ProviderSettings>().FirstOrDefault(p => string.Equals(p.Name, BusinessLogicClassConstants.ODataEndpointName, StringComparison.OrdinalIgnoreCase));
                Assert.IsNotNull(setting, "Did not find OData endpoint in config");

                // ValidateIntegratedMode
                this.CheckValidateIntegratedMode(cfg);

                // WebServer module
                this.CheckWebServerModule(cfg, WebConfigUtil.GetDomainServiceModuleTypeName());
            }
            catch (Exception ex)
            {
                Assert.Fail("Did not expect exception " + ex);
            }
            finally
            {
                File.Delete(tempConfigFile);
            }
        }
Exemplo n.º 5
0
        private IEnumerable<ConfigurationHttpModulesModel> ProcessHttpModules(HttpModulesSection httpModulesSection)
        {
            if (httpModulesSection == null)
            {
                return null;
            }

            var result = new List<ConfigurationHttpModulesModel>();
            foreach (HttpModuleAction httpModule in httpModulesSection.Modules)
            {
                var resultItem = new ConfigurationHttpModulesModel();
                resultItem.Name = httpModule.Name;
                resultItem.Type = httpModule.Type;

                result.Add(resultItem);
            }

            return result;
        }
Exemplo n.º 6
0
        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();
            }
        }