Microsoft.Web.Administration.Application.GetWebConfiguration C# (CSharp) Méthode

GetWebConfiguration() public méthode

public GetWebConfiguration ( ) : Configuration
Résultat Configuration
        public Configuration GetWebConfiguration()
        {
            if (_configuration != null)
            {
                return _configuration;
            }

            string root = null;
            foreach (VirtualDirectory child in VirtualDirectories)
            {
                if (child.Path == VirtualDirectory.RootPath)
                {
                    root = child.PhysicalPath;
                    break;
                }
            }

            if (this.IsRoot())
            {
                var server = Server.GetConfigurationCache().FileContext;
                if (root == null)
                {
                    var site = new Configuration(new FileContext(Server, null, server, Site.Name, false, false, this.Server.ReadOnly, (Entity as IXmlLineInfo).LineNumber));
                    return (_configuration = site);
                }
                else
                {
                    var physicalPath = Server.GetPhysicalPath(root);
                    var siteFile = System.IO.Path.Combine(physicalPath,
                        "web.config").ExpandIisExpressEnvironmentVariables();
                    Server.CleanSiteFile(siteFile);

                    // TODO: test ACL to set ReadOnly.
                    var site = new Configuration(new FileContext(Server, siteFile, server, Site.Name, false, false, this.Server.ReadOnly));
                    return (_configuration = site);
                }
            }

            string start = null;
            Configuration parent = null;
            while (parent == null)
            {
                var parentPath = (start ?? Path).GetParentPath();
                foreach (Application app in Site.Applications)
                {
                    if (app.Path != parentPath)
                    {
                        continue;
                    }

                    parent = app.GetWebConfiguration();
                    break;
                }

                if (start == parentPath)
                {
                    break;
                }

                start = parentPath;
            }

            if (root == null)
            {
                var app = new Configuration(new FileContext(Server, null, parent?.FileContext, Site.Name, false, false, this.Server.ReadOnly, (Entity as IXmlLineInfo).LineNumber));
                return (_configuration = app);
            }

            var fullPath = Site.Name + Path;
            var appFile = System.IO.Path.Combine(root, "web.config");
            // TODO: test ACL to set ReadOnly.
            return (_configuration = new Configuration(new FileContext(Server, appFile, parent?.FileContext, fullPath, false, false, this.Server.ReadOnly)));
        }

Usage Example

        public override void LoadPanels(MainForm mainForm, ServiceContainer serviceContainer, List <ModuleProvider> moduleProviders)
        {
            serviceContainer.RemoveService(typeof(IConfigurationService));
            serviceContainer.RemoveService(typeof(IControlPanel));
            var panel = new ApplicationPage(Application, mainForm);
            var scope = ManagementScope.Application;

            serviceContainer.AddService(typeof(IControlPanel), new ControlPanel());
            serviceContainer.AddService(typeof(IConfigurationService),
                                        new ConfigurationService(mainForm, Application.GetWebConfiguration(), scope, null, Application.Site,
                                                                 Application, null, null, this.Application.Location));
            foreach (var provider in moduleProviders)
            {
                if (!provider.SupportsScope(scope))
                {
                    continue;
                }

                var definition = provider.GetModuleDefinition(null);
                var type       = Type.GetType(definition.ClientModuleTypeName);
                if (type == null)
                {
                    continue;
                }

                if (!typeof(Module).IsAssignableFrom(type))
                {
                    continue;
                }

                var module = (Module)Activator.CreateInstance(type);
                module.Initialize(serviceContainer, null);
            }

            IModulePage page       = panel;
            var         mainModule = new MainModule();

            mainModule.Initialize(serviceContainer, null);
            page.Initialize(mainModule, null, null);
            mainForm.LoadPage(page);
        }
All Usage Examples Of Microsoft.Web.Administration.Application::GetWebConfiguration