Exemple #1
0
        public void OpenMachineConfiguration_serverNull()
        {
            _Configuration c1 = WebConfigurationManager.OpenMachineConfiguration("configTest", null);
            _Configuration c2 = ConfigurationManager.OpenMachineConfiguration();

            Assert.AreEqual(c1.FilePath, c2.FilePath, "A1");
        }
Exemple #2
0
 private ConfigurationSection GetConfigSection(string configSection, string appPath, string site, string location, bool useMachineConfig, out System.Configuration.Configuration config)
 {
     if (string.IsNullOrEmpty(appPath))
     {
         appPath = null;
     }
     if (string.IsNullOrEmpty(location))
     {
         location = null;
     }
     try
     {
         if (useMachineConfig)
         {
             config = WebConfigurationManager.OpenMachineConfiguration(location);
         }
         else
         {
             config = WebConfigurationManager.OpenWebConfiguration(appPath, site, location);
         }
     }
     catch (Exception exception)
     {
         if (useMachineConfig)
         {
             throw new Exception(System.Web.SR.GetString("Configuration_for_machine_config_not_found"), exception);
         }
         throw new Exception(System.Web.SR.GetString("Configuration_for_path_not_found", new object[] { appPath, string.IsNullOrEmpty(site) ? System.Web.SR.GetString("DefaultSiteName") : site }), exception);
     }
     return(config.GetSection(configSection));
 }
Exemple #3
0
        public void OpenMachineConfiguration_1()
        {
            _Configuration c1 = WebConfigurationManager.OpenMachineConfiguration();
            _Configuration c2 = ConfigurationManager.OpenMachineConfiguration();

            Assert.AreEqual(c1.FilePath, c2.FilePath, "A1");
        }
Exemple #4
0
        // </Snippet11>

        // <Snippet12>

        // Show how to use OpenMachineConfiguration(string, string).
        // It gets the machine.config file on the specified server,
        // applicabe to the specified reosurce, for the specified user
        // and displays section basic information.
        static void OpenMachineConfiguration4()
        {
            // Get the current user token.
            IntPtr userToken =
                System.Security.Principal.WindowsIdentity.GetCurrent().Token;

            // Get the machine.config file applicabe to the
            // specified reosurce, on the specified server for the
            // specified user.
            System.Configuration.Configuration config =
                WebConfigurationManager.OpenMachineConfiguration("configTest",
                                                                 "myServer", userToken);

            // Loop to get the sections. Display basic information.
            Console.WriteLine("Name, Allow Definition");
            int i = 0;

            foreach (ConfigurationSection section in config.Sections)
            {
                Console.WriteLine(
                    section.SectionInformation.Name + "\t" +
                    section.SectionInformation.AllowExeDefinition);
                i += 1;
            }
            Console.WriteLine("[Total number of sections: {0}]", i);

            // Display machine.config path.
            Console.WriteLine("[File path: {0}]", config.FilePath);
        }
Exemple #5
0
        // </Snippet12>

        // <Snippet13>

        // Show how to use OpenMachineConfiguration(string, string).
        // It gets the machine.config file on the specified server,
        // applicabe to the specified reosurce, for the specified user
        // and displays section basic information.
        static void OpenMachineConfiguration5()
        {
            // Set the user id and password.
            string user =
                System.Security.Principal.WindowsIdentity.GetCurrent().Name;
            // Substitute with actual password.
            string password = "******";

            // Get the machine.config file applicabe to the
            // specified reosurce, on the specified server for the
            // specified user.
            System.Configuration.Configuration config =
                WebConfigurationManager.OpenMachineConfiguration("configTest",
                                                                 "myServer", user, password);

            // Loop to get the sections. Display basic information.
            Console.WriteLine("Name, Allow Definition");
            int i = 0;

            foreach (ConfigurationSection section in config.Sections)
            {
                Console.WriteLine(
                    section.SectionInformation.Name + "\t" +
                    section.SectionInformation.AllowExeDefinition);
                i += 1;
            }
            Console.WriteLine("[Total number of sections: {0}]", i);

            // Display machine.config path.
            Console.WriteLine("[File path: {0}]", config.FilePath);
        }
Exemple #6
0
        private void UpdateRequestAndThreadsLimits()
        {
            TaskLogger.LogEnter();
            using (ServerManager serverManager = new ServerManager())
            {
                Configuration          applicationHostConfiguration = serverManager.GetApplicationHostConfiguration();
                ConfigurationSection   section   = applicationHostConfiguration.GetSection("system.webServer/serverRuntime");
                ConfigurationAttribute attribute = section.GetAttribute("appConcurrentRequestLimit");
                if (attribute != null && attribute.Schema != null && (long)attribute.Value == (long)((ulong)((uint)attribute.Schema.DefaultValue)))
                {
                    attribute.Value = 50000;
                    TaskLogger.Trace("Update applicationHost.config setting appConcurrentRequestLimit to {0}.", new object[]
                    {
                        attribute.Value
                    });
                }
                TaskLogger.Trace("Unlock system.webServer/serverRuntime for all web sites", new object[0]);
                section.OverrideMode = 2;
                serverManager.CommitChanges();
            }
            Configuration       configuration       = WebConfigurationManager.OpenMachineConfiguration();
            ProcessModelSection processModelSection = (ProcessModelSection)configuration.GetSection("system.web/processModel");
            bool flag = false;

            if (processModelSection.RequestQueueLimit == 5000)
            {
                processModelSection.RequestQueueLimit = 25000;
                flag = true;
                TaskLogger.Trace("Update machine.config setting requestQueueLimit to {0}.", new object[]
                {
                    processModelSection.RequestQueueLimit
                });
            }
            if (processModelSection.AutoConfig)
            {
                processModelSection.AutoConfig = false;
                flag = true;
                TaskLogger.Trace("Update machine.config autoconfig to false.", new object[0]);
            }
            if (processModelSection.MinWorkerThreads < 9)
            {
                processModelSection.MinWorkerThreads = 9;
                flag = true;
                TaskLogger.Trace("Update machine.config minWorkerThreads to {0}", new object[]
                {
                    processModelSection.MinWorkerThreads
                });
            }
            if (flag)
            {
                configuration.Save();
            }
            TaskLogger.LogExit();
        }
Exemple #7
0
        protected override void InternalExecute()
        {
            switch (this.configurationFileType)
            {
            case DotNetConfigurationFile.MachineConfig:
                this.Config = WebConfigurationManager.OpenMachineConfiguration();
                break;

            case DotNetConfigurationFile.WebConfig:
                this.Config = WebConfigurationManager.OpenWebConfiguration(this.Path, this.Site);
                break;

            default:
                this.Log.LogError("Task parameter ConfigurationFile has an unrecognized value.");
                return;
            }

            switch (this.TaskAction)
            {
            case RemoveAppSettingTaskAction:
                this.RemoveAppSetting(true);
                break;

            case RemoveConnectionStringTaskAction:
                this.RemoveConnectionString(true);
                break;

            case SetAppSettingTaskAction:
                this.SetAppSetting();
                break;

            case SetConnectionStringTaskAction:
                this.SetConnectionString();
                break;

            case ProtectConfigSectionAction:
                this.LogTaskMessage(string.Format(CultureInfo.InvariantCulture, "Protecting section '{0}' in {1}.", this.Section, this.Config.FilePath));
                ConfigurationSection cs = this.Config.Sections[this.Section];
                cs.SectionInformation.ProtectSection(this.ProtectionProvider);
                this.Save();
                break;

            case UnprotectConfigSectionAction:
                this.LogTaskMessage(string.Format(CultureInfo.InvariantCulture, "Unprotecting section '{0}' in {1}.", this.Section, this.Config.FilePath));
                ConfigurationSection cs2 = this.Config.Sections[this.Section];
                cs2.SectionInformation.UnprotectSection();
                this.Save();
                break;

            default:
                this.Log.LogError("Invalid task action: {0}.", this.TaskAction);
                break;
            }
        }
Exemple #8
0
        static void Main(string[] args)
        {
            Configuration machineConf = WebConfigurationManager.OpenMachineConfiguration();

            ConfigurationSectionGroup systemWeb     = machineConf.GetSectionGroup("system.web");
            ConfigurationSection      processModelS = systemWeb.Sections.Get("processModel");
            ProcessModelSection       processModel  = processModelS as ProcessModelSection;

            if (processModel != null)
            {
                processModel.MinIOThreads = 1;
                machineConf.Save();
            }
        }
Exemple #9
0
    protected void Page_Load(object sender, EventArgs e)
    {
        Configuration        config      = WebConfigurationManager.OpenMachineConfiguration("/");
        ConfigurationSection appSettings = config.GetSection("appSettings");

        if (appSettings.SectionInformation.IsProtected)
        {
            appSettings.SectionInformation.UnprotectSection();
        }
        else
        {
            appSettings.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
        }
        config.Save();
    }
Exemple #10
0
    public static T LoadConfigSection <T>(
        this ConfigurationSection configSection,
        string defaultName)
    {
        T _section = default(T);

        if (!String.IsNullOrEmpty(defaultName))
        {
            _section = (T)ConfigurationManager.GetSection(defaultName);
        }

        if (_section == null)
        {
            Configuration c = (null == HttpContext.Current) ?
                              ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None) :
                              WebConfigurationManager.OpenWebConfiguration("~");

            // lastly, try to find the specific NetTiersServiceSection for this assembly
            foreach (ConfigurationSection temp in c.Sections)
            {
                if (typeof(T) == temp.GetType())
                {
                    return((T)(object)temp);
                }
            }

            c = WebConfigurationManager.OpenMachineConfiguration();
            // lastly, try to find the specific NetTiersServiceSection for this assembly
            foreach (ConfigurationSection temp in c.Sections)
            {
                if (typeof(T) == temp.GetType())
                {
                    return((T)(object)temp);
                }
            }
        }

        if (_section != null)
        {
            return(_section);
        }
        else
        {
            throw new Exception(string.Format("section {0} could not be loaded", configSection.ToString()));
        }
    }
Exemple #11
0
        private ConfigurationSection GetConfigSection(string configSection, string appPath, string site, string location, bool useMachineConfig, out Configuration config)
        {
            if (string.IsNullOrEmpty(appPath))
            {
                appPath = null;
            }
            else
            {
                Debug.Assert(appPath.StartsWith("/", StringComparison.Ordinal), "This check is done in main.cxx in regiis");
            }

            if (string.IsNullOrEmpty(location))
            {
                location = null;
            }

            try {
                if (useMachineConfig)
                {
                    config = WebConfigurationManager.OpenMachineConfiguration(location);
                }
                else
                {
                    config = WebConfigurationManager.OpenWebConfiguration(appPath, site, location);
                }
            }
            catch (Exception e) {
                if (useMachineConfig)
                {
                    throw new Exception(SR.GetString(SR.Configuration_for_machine_config_not_found), e);
                }
                else
                {
                    throw new Exception(SR.GetString(SR.Configuration_for_path_not_found, appPath,
                                                     String.IsNullOrEmpty(site) ? SR.GetString(SR.DefaultSiteName) : site), e);
                }
            }

            return(config.GetSection(configSection));
        }
Exemple #12
0
        // </Snippet8>


        // Methods to access configuration files
        // not at runtime. These methods are
        // used to edit configuration files.


        // <Snippet9>

        // Show how to use OpenMachineConfiguration().
        // It gets the machine.config file on the current
        // machine and displays section information.
        static void OpenMachineConfiguration1()
        {
            // Get the machine.config file on the current machine.
            System.Configuration.Configuration config =
                WebConfigurationManager.OpenMachineConfiguration();

            // Loop to get the sections. Display basic information.
            Console.WriteLine("Name, Allow Definition");
            int i = 0;

            foreach (ConfigurationSection section in config.Sections)
            {
                Console.WriteLine(
                    section.SectionInformation.Name + "\t" +
                    section.SectionInformation.AllowExeDefinition);
                i += 1;
            }
            Console.WriteLine("[Total number of sections: {0}]", i);

            // Display machine.config path.
            Console.WriteLine("[File path: {0}]", config.FilePath);
        }
Exemple #13
0
        // </Snippet10>

        // <Snippet11>

        // Show how to use OpenMachineConfiguration(string, string).
        // It gets the machine.config file on the specified server and
        // applicabe to the specified reosurce and displays section
        // basic information.
        static void OpenMachineConfiguration3()
        {
            // Get the machine.config file applicabe to the
            // specified reosurce and on the specified server.
            System.Configuration.Configuration config =
                WebConfigurationManager.OpenMachineConfiguration("configTest",
                                                                 "myServer");

            // Loop to get the sections. Display basic information.
            Console.WriteLine("Name, Allow Definition");
            int i = 0;

            foreach (ConfigurationSection section in config.Sections)
            {
                Console.WriteLine(
                    section.SectionInformation.Name + "\t" +
                    section.SectionInformation.AllowExeDefinition);
                i += 1;
            }
            Console.WriteLine("[Total number of sections: {0}]", i);

            // Display machine.config path.
            Console.WriteLine("[File path: {0}]", config.FilePath);
        }
Exemple #14
0
    public static T LoadConfigSection <T>(
        this ConfigurationSection configSection,
        string defaultName,
        SectionDestination destination)
    {
        T _section = default(T);

        //Try to get a reference to the default <netTiersService> section
        if (!String.IsNullOrEmpty(defaultName))
        {
            switch (destination)
            {
            case SectionDestination.Website:
            case SectionDestination.Machine:
                _section = (T)WebConfigurationManager.GetSection(defaultName);
                break;

            case SectionDestination.Executable:
                _section = (T)ConfigurationManager.GetSection(defaultName);
                break;
            }
        }

        if (_section == null)
        {
            Configuration c = null;
            switch (destination)
            {
            case SectionDestination.Website:
                c = WebConfigurationManager.OpenWebConfiguration("~");
                break;

            case SectionDestination.Machine:
                c = WebConfigurationManager.OpenMachineConfiguration();
                break;

            case SectionDestination.Executable:
                c = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                break;
            }


            // lastly, try to find the specific NetTiersServiceSection for this assembly
            foreach (ConfigurationSection temp in c.Sections)
            {
                if (typeof(T) == temp.GetType())
                {
                    return((T)(object)temp);
                }
            }
        }

        if (_section != null)
        {
            return(_section);
        }
        else
        {
            throw new Exception(string.Format("section {0} could not be loaded", configSection.ToString()));
        }
    }