ASP.NET Configuration

Discussion in 'ASP.NET' started by MinalS, Sep 22, 2015.

  1. Overview of Configuration

    In the machine.config file, the values specific to the machine are defined. The settings of the configuration are managed by the system administrator. Users cannot access these files. It is present in the %runtime install path%\Config directory.

    The web.config file is used for overriding the default values. The configuration file can be extended locally, override or restrict the settings. The configuration element is the root node. The configuration handler and configuration section settings area are present in the configuration file.

    The syntax for the configuration file is as shown below:

    Code:
    <configuration>
        
        <configSections>
            <section name = "section1" type = "sectionhandler1" />
        </configSections>
    
        <section1>
            <setting1 attribute1 = ="attribute1" />
        </section1>
    
        <system.web>
            <authentication mode ="Windows" />
        </system.web>
    
    </configuration>
    
    
    Section handler declarations

    The section handlers are present in the <configSections> tags. The name and the file in which the configuration is present is specified. The configuration data is present.

    The syntax for the configuration sections is:

    Code:
    
    <configSections>
        <section />
        <sectionGroup />
        <remove />
        <clear />
    </configSections>
    
    
    The elements present in the section handler declarations are:
    1. Remove: The reference to section group and an inherited section is removed
    2. Clear: All the references to the inherited and section group are removed
    3. Section group: The association between the section handler and configuration section is defined
    4. Section: The association in the configuration element and section handler is defined
    Application and connection settings

    The application settings helps user to store the application name value pairs. The <appSettings> element is used for customizing the web application. User can add, remove or clear using the key / value pair inside the <appSettings> element.

    The general syntax for the application settings is as shown below:

    Code:
    
    <appSettings>
        < [ add | clear | remove ]  key = " configuration key value" value = "value" />
    </appSettings>
    
    
    Consider an example for adding the name of the student and registration number.

    Code:
    
    <configuration> 
        <appSettings>
            <add key = "appName" value = "John Smith" />
            <add key = "appRegNo" value = "10-30-20101" />
        </appSettings>
    </configuration>
    
    
    Connection settings are saved in key / value pair in an application configuration file. The elements can be add, remove and clear are the child elements.

    The following code example demonstrates the use of the connection string in the configuration file.

    Code:
    
    <?xml version = "1.0" encoding = ‘utf – 8’ ?>
        <configuration>
            <connectionStrings>
                <clear />
                <add name = "Name1" providerName = "System.Data.ProviderName" connectionString ="Connection String Name;" />
            </connectionStrings>
        </configuration>
    
    
    System.Web.Element


    The root element in the configuration section consisting of the configuration elements is defined.

    Code:
    
    <system.web>
        <anonymousIdentification>
        <authentication>
        <authorization>
        <browsercaps>
        <caching>
        <clientTarget>
        <compilation>
        <customErrors>
        <deployment>
        <deviceFilters>
        <globalization>
        <healthMonitoring>
        <hostingEnvironment>
        <httpCookies>
        <httpHandlers>
        <httpModules>
        <httpRuntime>
        <identity>
        <machinekey>
        <membership>
        <mobileControls>
        <pages>
        <processModel>
        <profile>
        <roleManager>
        <securityPolicy>
        <sessionPageState>
        <sessionState>
        <siteMap>
        <trace>
        <trust>
        <urlMappings>
        <webControls>
        <webParts>
        <webServices>
        <xhtmlConformance>
    </system.web>
    
    
    The various attributes, parent and child elements are described below:
    1. authentication : The authentication support is provided to the user.
    2. anonymousIdentification: The identification is configured for application authorization.
    3. authorization: The authorization support is provided
    4. compilation: All the compilation settings needed are provided to the user
    5. caching: The cache settings for the configuration are provided
    6. customErrors: The custom error messages are shown
    7. globalization: The globalization elements are defined
    8. healthMonitoring: The health monitoring for the application are described
    9. httpHandlers: The incoming URL requests are mapped to IHttpHandler classes
    10. httpCookies: The properties for the cookies are configured
    11. identity: The application identity for the web application is described
    12. membership: The parameters for handling the user account for ASP.NET membership
    13. pages: The page specific configuration settings are described
    14. roleManager: Role management for an application is defined
    15. securityPolicy: The valid mappings for the name security levels are defined
    16. trace: The trace service for an ASP.NET application is described
    17. urlMappings: The mapping is done with the user friendly URL.
    18. webParts: The web parts personalization provider is defined
    19. webservices: The setting of XML web service created using an ASP.NET application
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice