private static void Initialize()
 {
     if (!s_Initialized)
     {
         lock (s_InitLock)
         {
             if (!s_Initialized)
             {
                 AnonymousIdentificationSection anonymousIdentification = RuntimeConfig.GetAppConfig().AnonymousIdentification;
                 s_Enabled           = anonymousIdentification.Enabled;
                 s_CookieName        = anonymousIdentification.CookieName;
                 s_CookiePath        = anonymousIdentification.CookiePath;
                 s_CookieTimeout     = (int)anonymousIdentification.CookieTimeout.TotalMinutes;
                 s_RequireSSL        = anonymousIdentification.CookieRequireSSL;
                 s_SlidingExpiration = anonymousIdentification.CookieSlidingExpiration;
                 s_Protection        = anonymousIdentification.CookieProtection;
                 s_CookieMode        = anonymousIdentification.Cookieless;
                 s_Domain            = anonymousIdentification.Domain;
                 s_Modifier          = Encoding.UTF8.GetBytes("AnonymousIdentification");
                 if (s_CookieTimeout < 1)
                 {
                     s_CookieTimeout = 1;
                 }
                 if (s_CookieTimeout > 0x100a40)
                 {
                     s_CookieTimeout = 0x100a40;
                 }
                 s_Initialized = true;
             }
         }
     }
 }
示例#2
0
        public void CookiePath_validationFailure()
        {
            AnonymousIdentificationSection a = new AnonymousIdentificationSection();

            a.CookiePath = "";
            Assert.AreEqual("", a.CookiePath, "A1");
        }
示例#3
0
        public void CookieTimeout_validationFailure()
        {
            AnonymousIdentificationSection a = new AnonymousIdentificationSection();

            a.CookieTimeout = TimeSpan.FromSeconds(-30);
            Assert.AreEqual(TimeSpan.FromSeconds(-30), a.CookieTimeout, "A1");
        }
示例#4
0
        /// <summary>
        /// Adds web.config settings for windows authentication.
        /// </summary>
        internal void WriteConfigForWindowsAuth()
        {
            // Turn on Windows authentication
            AuthenticationSection authSection = _config.GetSection("system.web/authentication") as AuthenticationSection;

            authSection.Mode = AuthenticationMode.Windows;

            // Turn off anonymous auth
            AnonymousIdentificationSection anonSection = _config.GetSection("system.web/anonymousIdentification") as AnonymousIdentificationSection;

            anonSection.Enabled = false;
        }
示例#5
0
        /// <summary>
        /// Adds config settings for forms authentication.
        /// </summary>
        internal void WriteConfigForFormsAuth()
        {
            // Turn on forms authentication
            AuthenticationSection authSection = _config.GetSection("system.web/authentication") as AuthenticationSection;

            authSection.Mode           = AuthenticationMode.Forms;
            authSection.Forms.LoginUrl = "~/User/Login";

            // Turn on anonymous auth
            AnonymousIdentificationSection anonSection = _config.GetSection("system.web/anonymousIdentification") as AnonymousIdentificationSection;

            anonSection.Enabled = true;
        }
示例#6
0
        public void Defaults()
        {
            AnonymousIdentificationSection a = new AnonymousIdentificationSection();

            Assert.AreEqual(HttpCookieMode.UseCookies, a.Cookieless, "A1");
            Assert.AreEqual(".ASPXANONYMOUS", a.CookieName, "A2");
            Assert.AreEqual("/", a.CookiePath, "A3");
            Assert.AreEqual(CookieProtection.Validation, a.CookieProtection, "A4");
            Assert.AreEqual(false, a.CookieRequireSSL, "A5");
            Assert.AreEqual(true, a.CookieSlidingExpiration, "A6");
            Assert.AreEqual(TimeSpan.Parse("69.10:40:00"), a.CookieTimeout, "A7");
            Assert.AreEqual(null, a.Domain, "A8");
            Assert.AreEqual(false, a.Enabled, "A9");
        }
示例#7
0
        public void Init(HttpApplication app)
        {
            this.app = app;
            app.PostMapRequestHandler += OnEnter;
            app.EndRequest            += OnLeave;

            AnonymousIdentificationSection anonymousConfig =
                (AnonymousIdentificationSection)WebConfigurationManager.GetSection("system.web/anonymousIdentification");

            if (anonymousConfig == null)
            {
                return;
            }

            anonymousCookieName = anonymousConfig.CookieName;
        }
示例#8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sectionName"></param>
        /// <returns></returns>
        public static ConfigurationSection GetSection(string sectionName)
        {
            ConfigurationSection section = new AnonymousIdentificationSection();
            //实际中应该加上缓存,本次不加

            ConfigFilesSetting settings = loadFilesSetting(null);

            System.Configuration.Configuration config = getFinalConfiguration(settings);
            section = config.GetSection(sectionName);

            if (section == null || section is DefaultSection)
            {
                section = GetSectionFromGroups(sectionName, config.SectionGroups);
            }


            return(section);
        }
        public void WriteConfigForWindowsAuth_Should_Set_WindowsAuthMode_And_Disable_AnonymousIdentification()
        {
            // Arrange
            string configFilePath = GetConfigPath("test.config");

            // Act
            FullTrustConfigReaderWriter configManager = new FullTrustConfigReaderWriter(configFilePath);

            configManager.WriteConfigForWindowsAuth();

            // Assert
            Configuration         config      = configManager.GetConfiguration();
            AuthenticationSection authSection = config.GetSection("system.web/authentication") as AuthenticationSection;

            Assert.That(authSection, Is.Not.Null);
            Assert.That(authSection.Mode, Is.EqualTo(AuthenticationMode.Windows));
            Assert.That(authSection.Forms.LoginUrl, Is.EqualTo("login.aspx"));             // login.aspx is the default for windows auth

            AnonymousIdentificationSection anonSection = config.GetSection("system.web/anonymousIdentification") as AnonymousIdentificationSection;

            Assert.That(anonSection.Enabled, Is.False);
        }
        public void WriteConfigForFormsAuth_Should_Add_FormsAuth_Section_And_AnonymousIdentification()
        {
            // Arrange
            string configFilePath = GetConfigPath("test.config");

            // Act
            FullTrustConfigReaderWriter configManager = new FullTrustConfigReaderWriter(configFilePath);

            configManager.WriteConfigForFormsAuth();

            // Assert
            Configuration         config      = configManager.GetConfiguration();
            AuthenticationSection authSection = config.GetSection("system.web/authentication") as AuthenticationSection;

            Assert.That(authSection, Is.Not.Null);
            Assert.That(authSection.Mode, Is.EqualTo(AuthenticationMode.Forms));
            Assert.That(authSection.Forms.LoginUrl, Is.EqualTo("~/User/Login"));

            AnonymousIdentificationSection anonSection = config.GetSection("system.web/anonymousIdentification") as AnonymousIdentificationSection;

            Assert.That(anonSection.Enabled, Is.True);
        }
示例#11
0
        /////////////////////////////////////////////////////////////////////////////
        /////////////////////////////////////////////////////////////////////////////
        /////////////////////////////////////////////////////////////////////////////
        // Static functions
        private static void Initialize()
        {
            if (s_Initialized)
            {
                return;
            }

            lock (s_InitLock) {
                if (s_Initialized)
                {
                    return;
                }

                AnonymousIdentificationSection settings = RuntimeConfig.GetAppConfig().AnonymousIdentification;
                s_Enabled           = settings.Enabled;
                s_CookieName        = settings.CookieName;
                s_CookiePath        = settings.CookiePath;
                s_CookieTimeout     = (int)settings.CookieTimeout.TotalMinutes;
                s_RequireSSL        = settings.CookieRequireSSL;
                s_SlidingExpiration = settings.CookieSlidingExpiration;
                s_Protection        = settings.CookieProtection;
                s_CookieMode        = settings.Cookieless;
                s_Domain            = settings.Domain;

                s_Modifier = Encoding.UTF8.GetBytes("AnonymousIdentification");
                if (s_CookieTimeout < 1)
                {
                    s_CookieTimeout = 1;
                }
                if (s_CookieTimeout > 60 * 24 * 365 * 2)
                {
                    s_CookieTimeout = 60 * 24 * 365 * 2; // 2 years
                }
                s_Initialized = true;
            }
        }
        static void Main(string[] args)
        {
            // <Snippet2>
            // Get the applicaqtion configuration.
            Configuration configuration =
                WebConfigurationManager.OpenWebConfiguration(
                    "/aspnetTest");

            // Get the section.
            AnonymousIdentificationSection anonymousIdentificationSection =
                (AnonymousIdentificationSection)configuration.GetSection(
                    "system.web/anonymousIdentification");

            // </Snippet2>


            // <Snippet3>
            // Get Cookieless.
            System.Web.HttpCookieMode cookieless =
                anonymousIdentificationSection.Cookieless;
            Console.WriteLine("Cookieless: {0}",
                              cookieless);
            // </Snippet3>

            // <Snippet4>
            // Get CookieName.
            string cookieName =
                anonymousIdentificationSection.CookieName;

            Console.WriteLine("Cookie name: {0}",
                              cookieName);
            // </Snippet4>

            // <Snippet5>
            // Get CookiePath.
            string cookiePath =
                anonymousIdentificationSection.CookiePath;

            Console.WriteLine("Cookie path: {0}", cookiePath);
            // </Snippet5>

            // <Snippet6>
            // Get CookieProtection.
            System.Web.Security.CookieProtection cookieProtection =
                anonymousIdentificationSection.CookieProtection;
            Console.WriteLine("Cookie protection: {0}",
                              cookieProtection);
            // </Snippet6>

            // <Snippet7>
            // Get CookieRequireSSL.
            bool cookieRequireSSL =
                anonymousIdentificationSection.CookieRequireSSL;

            Console.WriteLine("Cookie require SSL: {0}",
                              cookieRequireSSL.ToString());
            // </Snippet7>

            // <Snippet8>
            // Get CookieSlidingExpiration.
            bool cookieSlidingExpiration =
                anonymousIdentificationSection.CookieSlidingExpiration;

            Console.WriteLine("Cookie sliding expiration: {0}",
                              cookieSlidingExpiration.ToString());
            // </Snippet8>

            // <Snippet9>
            // Get CookieTimeout.
            TimeSpan cookieTimeout =
                anonymousIdentificationSection.CookieTimeout;

            Console.WriteLine("Cookie timeout: {0}",
                              cookieTimeout.ToString());
            // </Snippet9>


            // <Snippet10>
            // Get Domain.
            string domain =
                anonymousIdentificationSection.Domain;

            Console.WriteLine("Anonymous identification domain: {0}",
                              domain);
            // </Snippet10>

            // <Snippet11>
            // Get Enabled.
            bool aIdEnabled =
                anonymousIdentificationSection.Enabled;

            Console.WriteLine("Anonymous identification enabled: {0}",
                              aIdEnabled.ToString());
            // </Snippet11>
        }
        static void Main(string[] args)
        {
            try
            {
                // Set the path of the config file.
                string configPath = "";

                // Get the Web application configuration object.
                Configuration config =
                    WebConfigurationManager.OpenWebConfiguration(configPath);

                // Get the section related object.
                AnonymousIdentificationSection configSection =
                    (AnonymousIdentificationSection)config.GetSection
                        ("system.web/anonymousIdentification");

                // Display title and info.
                Console.WriteLine("Configuration Info");
                Console.WriteLine();

                // Display Config details.
                Console.WriteLine("File Path: {0}",
                                  config.FilePath);
                Console.WriteLine("Section Path: {0}",
                                  configSection.SectionInformation.Name);
                Console.WriteLine();

                // <Snippet2>
                // Create a ConfigurationLockCollection object.
                ConfigurationLockCollection lockedAttribList;
                lockedAttribList = configSection.LockAttributes;
                // </Snippet2>

                // <Snippet3>
                // Add an attribute to the lock collection.
                if (!lockedAttribList.Contains("enabled"))
                {
                    lockedAttribList.Add("enabled");
                }
                // </Snippet3>
                if (!lockedAttribList.Contains("cookieless"))
                {
                    lockedAttribList.Add("cookieless");
                }

                // <Snippet4>
                // Count property.
                Console.WriteLine("Collection Count: {0}",
                                  lockedAttribList.Count);
                // </Snippet4>

                // <Snippet5>
                // AttributeList method.
                Console.WriteLine("AttributeList: {0}",
                                  lockedAttribList.AttributeList);
                // </Snippet5>

                // <Snippet6>
                // Contains method.
                Console.WriteLine("Contains 'enabled': {0}",
                                  lockedAttribList.Contains("enabled"));
                // </Snippet6>

                // <Snippet7>
                // HasParentElements property.
                Console.WriteLine("HasParentElements: {0}",
                                  lockedAttribList.HasParentElements);
                // </Snippet7>

                // <Snippet8>
                // IsModified property.
                Console.WriteLine("IsModified: {0}",
                                  lockedAttribList.IsModified);
                // </Snippet8>

                // <Snippet9>
                // IsReadOnly method.
                Console.WriteLine("IsReadOnly: {0}",
                                  lockedAttribList.IsReadOnly("enabled"));
                // </Snippet9>

                // <Snippet10>
                // Remove a configuration object
                // from the collection.
                lockedAttribList.Remove("cookieless");
                // </Snippet10>

                // <Snippet11>
                // Clear the collection.
                lockedAttribList.Clear();
                // </Snippet11>

                // <Snippet12>
                // Create an ArrayList to contain
                // the property items of the configuration
                // section.
                ArrayList configPropertyAL = new ArrayList(lockedAttribList.Count);
                foreach (PropertyInformation propertyItem in
                         configSection.ElementInformation.Properties)
                {
                    configPropertyAL.Add(propertyItem.Name.ToString());
                }
                // Copy the elements of the ArrayList to a string array.
                String[] myArr = (String[])configPropertyAL.ToArray(typeof(string));
                // Create as a comma delimited list.
                string propList = string.Join(",", myArr);
                // Lock the items in the list.
                lockedAttribList.SetFromList(propList);
                // </Snippet12>
            }

            catch (Exception e)
            {
                // Unknown error.
                Console.WriteLine(e.ToString());
            }

            // Display and wait.
            Console.ReadLine();
        }
示例#14
0
        static void Main(string[] args)
        {
            try
            {
                // Set the path of the config file.
                // Make sure that you have a Web site on the
                // same server called TestConfig.
                string configPath = "/TestConfig";

                // Get the Web application configuration object.
                Configuration config =
                    WebConfigurationManager.OpenWebConfiguration(configPath);

                // Get the section related object.
                AnonymousIdentificationSection configSection =
                    (AnonymousIdentificationSection)config.GetSection
                        ("system.web/anonymousIdentification");

                // Display title and info.
                Console.WriteLine("Configuration Info");
                Console.WriteLine();

                // Display Config details.
                Console.WriteLine("File Path: {0}",
                                  config.FilePath);
                Console.WriteLine("Section Path: {0}",
                                  configSection.SectionInformation.Name);
                Console.WriteLine();

                // Create a NameValueConfigurationCollection object.
                NameValueConfigurationCollection myNameValConfigCollection =
                    new NameValueConfigurationCollection();

                foreach (PropertyInformation propertyItem in
                         configSection.ElementInformation.Properties)
                {
                    // Assign  domain name.
                    if (propertyItem.Name == "domain")
                    {
                        propertyItem.Value = "MyDomain";
                    }

                    if (propertyItem.Value != null)
                    {
                        // Enable SSL for cookie exchange.
                        if (propertyItem.Name == "cookieRequireSSL")
                        {
                            propertyItem.Value = true;
                        }

                        NameValueConfigurationElement nameValConfigElement =
                            new NameValueConfigurationElement
                                (propertyItem.Name.ToString(), propertyItem.Value.ToString());

                        // Add a NameValueConfigurationElement
                        // to the collection.
                        myNameValConfigCollection.Add(nameValConfigElement);
                    }
                }

                // Count property.
                Console.WriteLine("Collection Count: {0}",
                                  myNameValConfigCollection.Count);

                // Item property.
                Console.WriteLine("Value of property 'enabled': {0}",
                                  myNameValConfigCollection["enabled"].Value);

                // Display the contents of the collection.
                foreach (NameValueConfigurationElement configItem
                         in myNameValConfigCollection)
                {
                    Console.WriteLine();
                    Console.WriteLine("Configuration Details:");
                    Console.WriteLine("Name: {0}", configItem.Name);
                    Console.WriteLine("Value: {0}", configItem.Value);
                }

                // Assign the domain calue.
                configSection.Domain = myNameValConfigCollection["domain"].Value;
                // Assign the SSL required value.
                if (myNameValConfigCollection["cookieRequireSSL"].Value == "true")
                {
                    configSection.CookieRequireSSL = true;
                }

                // Remove domain from the collection.
                NameValueConfigurationElement myConfigElement =
                    myNameValConfigCollection["domain"];
                // Remove method.
                myNameValConfigCollection.Remove(myConfigElement);

                // Save changes to the configuration file.
                // This modifies the Web.config of the TestConfig site.
                config.Save(ConfigurationSaveMode.Minimal, true);

                // Clear the collection.
                myNameValConfigCollection.Clear();
            }

            catch (Exception e)
            {
                // Unknown error.
                Console.WriteLine(e.ToString());
            }

            // Display and wait.
            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            try
            {
                // Set the path of the config file.
                string configPath = "";

                // Get the Web application configuration object.
                Configuration config =
                    WebConfigurationManager.OpenWebConfiguration(configPath);

                // Get the section related object.
                AnonymousIdentificationSection configSection =
                    (AnonymousIdentificationSection)config.GetSection
                        ("system.web/anonymousIdentification");

                // Display title.
                Console.WriteLine("Configuration PropertyInformation");
                Console.WriteLine("Section: anonymousIdentification");

                // Instantiate a new PropertyInformationCollection object.
                PropertyInformationCollection propCollection =
                    configSection.ElementInformation.Properties;

                // Display Collection Count.
                Console.WriteLine("Collection Count: {0}",
                                  propCollection.Count);

                // Display properties of elements
                // of the PropertyInformationCollection.
                foreach (PropertyInformation propertyItem in propCollection)
                {
                    Console.WriteLine();
                    Console.WriteLine("Property Details:");

                    // <Snippet8>
                    // Display the Name property.
                    Console.WriteLine("Name: {0}", propertyItem.Name);
                    // </Snippet8>

                    // <Snippet12>
                    // Display the Value property.
                    Console.WriteLine("Value: {0}", propertyItem.Value);
                    // </Snippet12>

                    // <Snippet2>
                    // Display the DefaultValue property.
                    Console.WriteLine("DefaultValue: {0}",
                                      propertyItem.DefaultValue);
                    // </Snippet2>

                    // <Snippet10>
                    // Display the Type property.
                    Console.WriteLine("Type: {0}", propertyItem.Type);
                    // </Snippet10>

                    // <Snippet3>
                    // Display the IsKey property.
                    Console.WriteLine("IsKey: {0}", propertyItem.IsKey);
                    // </Snippet3>

                    // <Snippet4>
                    // Display the IsLocked property.
                    Console.WriteLine("IsLocked: {0}", propertyItem.IsLocked);
                    // </Snippet4>

                    // <Snippet5>
                    // Display the IsModified property.
                    Console.WriteLine("IsModified: {0}", propertyItem.IsModified);
                    // </Snippet5>

                    // <Snippet6>
                    // Display the IsRequired property.
                    Console.WriteLine("IsRequired: {0}", propertyItem.IsRequired);
                    // </Snippet6>

                    // <Snippet7>
                    // Display the LineNumber property.
                    Console.WriteLine("LineNumber: {0}", propertyItem.LineNumber);
                    // </Snippet7>

                    // <Snippet9>
                    // Display the Source property.
                    Console.WriteLine("Source: {0}", propertyItem.Source);
                    // </Snippet9>

                    // <Snippet11>
                    // Display the Validator property.
                    Console.WriteLine("Validator: {0}", propertyItem.Validator);
                    // </Snippet11>

                    // <Snippet13>
                    // Display the ValueOrigin property.
                    Console.WriteLine("ValueOrigin: {0}", propertyItem.ValueOrigin);
                    // </Snippet13>
                }

                Console.WriteLine("");
                Console.WriteLine("Configuration - Accessing an Attribute");
                // <Snippet14>
                // Create EllementInformation object.
                ElementInformation elementInfo =
                    configSection.ElementInformation;
                // Create a PropertyInformationCollection object.
                PropertyInformationCollection propertyInfoCollection =
                    elementInfo.Properties;
                // Create a PropertyInformation object.
                PropertyInformation myPropertyInfo =
                    propertyInfoCollection["enabled"];
                // Display the property value.
                Console.WriteLine
                    ("anonymousIdentification Section - Enabled: {0}",
                    myPropertyInfo.Value);
                // </Snippet14>
            }

            catch (Exception e)
            {
                // Error.
                Console.WriteLine(e.ToString());
            }

            // Display and wait.
            Console.ReadLine();
        }
示例#16
0
        static void Main(string[] args)
        {
            string inputStr = String.Empty;
            string option   = String.Empty;

            // Define a regular expression to allow only
            // alphanumeric inputs that are at most 20 character
            // long. For instance "/iii:".
            Regex rex = new Regex(@"[^\/w]{1,20}:");

            // Parse the user's input.
            if (args.Length < 1)
            {
                // No option entered.
                Console.Write("Input parameter missing.");
                return;
            }
            else
            {
                // Get the user's option.
                inputStr = args[0].ToLower();
                if (!(rex.Match(inputStr)).Success)
                {
                    // Wrong option format used.
                    Console.Write("Input parameter format not allowed.");
                    return;
                }
            }

            // <Snippet1>

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

            // Get the <system.web> group.
            SystemWebSectionGroup systemWeb =
                (SystemWebSectionGroup)configuration.GetSectionGroup("system.web");

            // </Snippet1>


            try
            {
                switch (inputStr)
                {
                case "/anonymous:":
                    // <Snippet2>
                    // Get the anonymousIdentification section.
                    AnonymousIdentificationSection
                        anonymousIdentification =
                        systemWeb.AnonymousIdentification;
                    // Read section information.
                    info =
                        anonymousIdentification.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet2>

                    Console.Write(msg);
                    break;

                case "/authentication:":

                    // <Snippet3>
                    // Get the authentication section.
                    AuthenticationSection authentication =
                        systemWeb.Authentication;
                    // Read section information.
                    info =
                        authentication.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet3>

                    Console.Write(msg);
                    break;

                case "/authorization:":

                    // <Snippet4>
                    // Get the authorization section.
                    AuthorizationSection authorization =
                        systemWeb.Authorization;
                    // Read section information.
                    info =
                        authorization.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet4>

                    Console.Write(msg);
                    break;

                case "/compilation:":

                    // <Snippet5>
                    // Get the compilation section.
                    CompilationSection compilation =
                        systemWeb.Compilation;
                    // Read section information.
                    info =
                        compilation.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet5>

                    Console.Write(msg);
                    break;


                case "/customerrors:":

                    // <Snippet6>
                    // Get the customerrors section.
                    CustomErrorsSection customerrors =
                        systemWeb.CustomErrors;
                    // Read section information.
                    info =
                        customerrors.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet6>

                    Console.Write(msg);
                    break;

                case "/globalization:":

                    // <Snippet7>
                    // Get the globalization section.
                    GlobalizationSection globalization =
                        systemWeb.Globalization;
                    // Read section information.
                    info =
                        globalization.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet7>

                    Console.Write(msg);
                    break;

                case "/httpcookies:":
                    // <Snippet8>
                    // Get the httpCookies section.
                    HttpCookiesSection httpCookies =
                        systemWeb.HttpCookies;
                    // Read section information.
                    info =
                        httpCookies.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet8>

                    Console.Write(msg);
                    break;

                case "/httphandlers:":

                    // <Snippet9>
                    // Get the httpHandlers section.
                    HttpHandlersSection httpHandlers =
                        systemWeb.HttpHandlers;
                    // Read section information.
                    info =
                        httpHandlers.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet9>

                    Console.Write(msg);
                    break;

                case "/httpmodules:":

                    // <Snippet10>
                    // Get the httpModules section.
                    HttpModulesSection httpModules =
                        systemWeb.HttpModules;
                    // Read section information.
                    info =
                        httpModules.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet10>

                    Console.Write(msg);
                    break;

                case "/httpruntime:":

                    // <Snippet11>
                    // Get the httpRuntime section.
                    HttpRuntimeSection httpRuntime =
                        systemWeb.HttpRuntime;
                    // Read section information.
                    info =
                        httpRuntime.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet11>

                    Console.Write(msg);
                    break;

                case "/identity:":

                    // <Snippet12>
                    // Get the identity section.
                    IdentitySection identity =
                        systemWeb.Identity;
                    // Read section information.
                    info =
                        identity.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet12>

                    Console.Write(msg);
                    break;

                case "/machinekey:":

                    // <Snippet13>
                    // Get the machineKey section.
                    MachineKeySection machineKey =
                        systemWeb.MachineKey;
                    // Read section information.
                    info =
                        machineKey.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet13>

                    Console.Write(msg);
                    break;

                case "/membership:":
                    // <Snippet14>
                    // Get the membership section.
                    MembershipSection membership =
                        systemWeb.Membership;
                    // Read section information.
                    info =
                        membership.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet14>

                    Console.Write(msg);
                    break;

                case "/pages:":
                    // <Snippet15>
                    // Get the pages section.
                    PagesSection pages =
                        systemWeb.Pages;
                    // Read section information.
                    info =
                        pages.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet15>

                    Console.Write(msg);
                    break;

                case "/processModel:":
                    // <Snippet16>
                    // Get the processModel section.
                    ProcessModelSection processModel =
                        systemWeb.ProcessModel;
                    // Read section information.
                    info =
                        processModel.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet16>

                    Console.Write(msg);
                    break;

                case "/profile:":
                    // <Snippet17>
                    // Get the profile section.
                    ProfileSection profile =
                        systemWeb.Profile;
                    // Read section information.
                    info =
                        profile.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet17>

                    Console.Write(msg);
                    break;

                case "/roleManager:":
                    // <Snippet18>
                    // Get the roleManager section.
                    RoleManagerSection roleManager =
                        systemWeb.RoleManager;
                    // Read section information.
                    info =
                        roleManager.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet18>

                    Console.Write(msg);
                    break;

                case "/securityPolicy:":
                    // <Snippet19>
                    // Get the securityPolicy section.
                    SecurityPolicySection securityPolicy =
                        systemWeb.SecurityPolicy;
                    // Read section information.
                    info =
                        securityPolicy.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet19>

                    Console.Write(msg);
                    break;

                case "/sessionState:":
                    // <Snippet20>
                    // Get the sessionState section.
                    SessionStateSection sessionState =
                        systemWeb.SessionState;
                    // Read section information.
                    info =
                        sessionState.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet20>

                    Console.Write(msg);
                    break;

                case "/sitemap:":
                    // <Snippet21>
                    // Get the siteMap section.
                    SiteMapSection siteMap =
                        systemWeb.SiteMap;
                    // Read section information.
                    info =
                        siteMap.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet21>

                    Console.Write(msg);
                    break;

                case "/trace:":
                    // <Snippet22>
                    // Get the trace section.
                    TraceSection trace =
                        systemWeb.Trace;
                    // Read section information.
                    info =
                        trace.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet22>

                    Console.Write(msg);
                    break;

                case "/trust:":
                    // <Snippet23>
                    // Get the trust section.
                    TrustSection trust =
                        systemWeb.Trust;
                    // Read section information.
                    info =
                        trust.SectionInformation;
                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet23>

                    Console.Write(msg);
                    break;

                case "/browserCaps:":
                    // <Snippet24>
                    // Get the browserCaps section.
                    DefaultSection browserCaps =
                        systemWeb.BrowserCaps;
                    // Read section information.
                    info =
                        browserCaps.SectionInformation;

                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet24>

                    Console.Write(msg);
                    break;

                case "/clientTarget:":
                    // <Snippet25>
                    // Get the clientTarget section.
                    ClientTargetSection clientTarget =
                        systemWeb.ClientTarget;
                    // Read section information.
                    info =
                        clientTarget.SectionInformation;

                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet25>

                    Console.Write(msg);
                    break;


                case "/deployment:":
                    // <Snippet26>
                    // Get the deployment section.
                    DeploymentSection deployment =
                        systemWeb.Deployment;
                    // Read section information.
                    info =
                        deployment.SectionInformation;

                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet26>

                    Console.Write(msg);
                    break;


                case "/deviceFilters:":
                    // <Snippet27>
                    // Get the deviceFilters section.
                    DefaultSection deviceFilters =
                        systemWeb.DeviceFilters;
                    // Read section information.
                    info =
                        deviceFilters.SectionInformation;

                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet27>

                    Console.Write(msg);
                    break;

                case "/healthMonitoring:":
                    // <Snippet28>
                    // Get the healthMonitoring section.
                    HealthMonitoringSection healthMonitoring =
                        systemWeb.HealthMonitoring;
                    // Read section information.
                    info =
                        healthMonitoring.SectionInformation;

                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet28>

                    Console.Write(msg);
                    break;

                case "/hostingEnvironment:":
                    // <Snippet29>
                    // Get the hostingEnvironment section.
                    HostingEnvironmentSection hostingEnvironment =
                        systemWeb.HostingEnvironment;
                    // Read section information.
                    info =
                        hostingEnvironment.SectionInformation;

                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet29>

                    Console.Write(msg);
                    break;

                case "/mobileControls:":
                    // <Snippet30>
                    // Get the mobileControls section.
                    ConfigurationSection mobileControls =
                        systemWeb.MobileControls;
                    // Read section information.
                    info =
                        mobileControls.SectionInformation;

                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet30>

                    Console.Write(msg);
                    break;

                case "/protocols:":
                    // <Snippet31>
                    // Get the protocols section.
                    DefaultSection protocols =
                        systemWeb.Protocols;
                    // Read section information.
                    info =
                        protocols.SectionInformation;

                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet31>

                    Console.Write(msg);
                    break;

                case "/urlMappings:":
                    // <Snippet32>
                    // Get the urlMappings section.
                    UrlMappingsSection urlMappings =
                        systemWeb.UrlMappings;
                    // Read section information.
                    info =
                        urlMappings.SectionInformation;

                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet32>

                    Console.Write(msg);
                    break;

                case "/webControls:":
                    // <Snippet33>
                    // Get the webControls section.
                    WebControlsSection webControls =
                        systemWeb.WebControls;
                    // Read section information.
                    info =
                        webControls.SectionInformation;

                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet33>

                    Console.Write(msg);
                    break;

                case "/webParts:":
                    // <Snippet34>
                    // Get the webParts section.
                    WebPartsSection webParts =
                        systemWeb.WebParts;
                    // Read section information.
                    info =
                        webParts.SectionInformation;

                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet34>

                    Console.Write(msg);
                    break;

                case "/webServices:":
                    // <Snippet35>
                    // Get the webServices section.
                    WebServicesSection webServices =
                        systemWeb.WebServices;
                    // Read section information.
                    info =
                        webServices.SectionInformation;

                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();
                    msg      = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet35>

                    Console.Write(msg);
                    break;

                case "/XhtmlConformance:":
                    // <Snippet36>
                    // Get the xhtmlConformance section.
                    XhtmlConformanceSection xhtmlConformance =
                        systemWeb.XhtmlConformance;
                    // Read section information.
                    info =
                        xhtmlConformance.SectionInformation;

                    name     = info.SectionName;
                    type     = info.Type;
                    declared = info.IsDeclared.ToString();

                    msg = String.Format(
                        "Name:     {0}\nDeclared: {1}\nType:     {2}\n",
                        name, declared, type);
                    // </Snippet36>

                    Console.Write(msg);
                    break;


                case "/all:":
                    StringBuilder             allSections    = new StringBuilder();
                    ConfigurationSectionGroup systemWebGroup =
                        configuration.GetSectionGroup("system.web");
                    int i = 0;
                    foreach (ConfigurationSection section in
                             systemWebGroup.Sections)
                    {
                        i       += 1;
                        info     = section.SectionInformation;
                        name     = info.SectionName;
                        type     = info.Type;
                        declared = info.IsDeclared.ToString();
                        if (i < 10)
                        {
                            msg = String.Format(
                                "{0})Name:   {1}\nDeclared: {2}\nType:     {3}\n",
                                i.ToString(), name, declared, type);
                        }
                        else
                        {
                            msg = String.Format(
                                "{0})Name:  {1}\nDeclared: {2}\nType:     {3}\n",
                                i.ToString(), name, declared, type);
                        }
                        allSections.AppendLine(msg);
                    }

                    // Console.WriteLine(systemWebGroup.Name);
                    // Console.WriteLine(systemWebGroup.SectionGroupName);

                    Console.Write(allSections.ToString());
                    break;

                default:
                    // Option is not allowed..
                    Console.Write("Input not allowed.");
                    break;
                }
            }
            catch (ArgumentException e)
            {
                // Never display this. Use it for
                // debugging purposes.
                msg = e.ToString();
            }
        }