-->

23 February 2020

asp.net Web.config

  Asp.Net CS By Example       23 February 2020

 Web.config 

  Almost every ASP.NET web application contains a file named Web.config, which stores various application settings. By default, all .NET web applications are configured in the Machine.config file, which contains machine-wide settings. This file should rarely be changed, but if we must, the file lives in the.

 C:\WINDOWS\Microsoft.NET\Framework\version\CONFIG directory 

 For the most part, all our configuration settings will be part of the web.config file in the root directory of our application. We won’t want to make any modifications to this file.

 The web.config file is included by default when creating a new project in Visual Web Developer, but if any reason we need to re-create the file (after accidentally deleting it for example). To add web.config file follow below steps:
  => Right click On Project.
  => select 'Add' Menu
  => select 'New Item' Menu
  => select 'Web' Setcion in Visual C#.
  => Now Select 'Web Configuration File' form from the dialog that appears.
  => Give a meaningful Name to 'Web Configuration File' E.g. 'Web.config'
  => And Last step is click On 'Add' Button.

  The Web.config file is an XML file that can hold configuration settings for the application in which the file resides.One of the most useful settings that Web.config controls is ASP.NET’s debug mode.If Visual Web Developer hasn’t enabled debug mode for we, we can do it ourself by opening Web.config and editing the compilation element, which looks like this:

 <compilation debug="true" strict="false" explicit="true" /> 

Web.config can also be used to store custom information for our application in a central location that’s accessible from all the pages of our site. For example, if we want to store the email address of someone in our technical support team so that it can be changed easily, we might take the approach shown here:

  Code: Web.config
 <configuration>
  <appSettings>
     <add key="SupportEmail" value="support@gmail.com" /> 
  </appSettings>
  <connectionStrings>
    <add name="LearnAsp" connectionString="data source=LearnAsp;user id=LearnAsp; 
      password=LearnAsp; Pooling=true; Max pool size=20; Min pool size=0;"/>
  </connectionStrings>
 </configuration>

This way, whenever we need to display or use an email address for technical support within the site, we can simply read the SupportEmail key using the WebConfigurationManager class. And, if we wanted to change the email address we used for technical support, we’d just need to change this setting in Web.config.

 We can configure almost all functional items of ASP.NET through the configuration files. The options available to we using the default ASP.NET machine.config file include everything from browser compatibility options to secure authentication options.In Below Table given the details the standard tags available through the ASP.NET configuration files; however, we can define additional tags by defining new configuration section handlers

Here are Standard Configuration Tags:

Sr.No Configuration Group Tag Description
1) <appSettings> Application Allows the configuration of custom settings for our applications.
2) <connectionStrings> Application Allows the configuration of database connection settings for our applications.
3) <authentication> Security Allows configuration of ASP.NET’s authentication support.
4) <authenticationModules> Security Allows the definition of modules necessary for ASP.NET’s authentication support.
5) <authorization> Security Allows configuration of ASP.NET’s authorization support.
6) <browserCaps> System Allows configuration of settings for the browser capabilities component.
7) <compilation> System Allows configuration of all ASP.NET compilation settings.
8) <connectionManagement> System Allows configuration of client connection options.
9) <customErrors> System Allows the definition of custom error messages for our application.
10) <defaultProxy> System Allows the configuration of proxy server usage by ASP.NET.
11) <globalization> Application Allows the configuration of globalization settings for our applications.
12) <httpHandlers> System Allows mapping of incoming URL requests to appropriate IHttpHandler classes or IhttpHandlerFactory classes
13) <httpModules> System Allows the configuration of HTTP modules used within an application.
14) <httpRuntime> System Allows the configuration of HTTP runtime settings.
15) <identity> Application Controls the identity used by our application.
16) <machineKey> Security Allows configuration of keys for encryption and decryption of form’s authentication cookie data.
17) <pages> Application Allows configuration of page-specific settings.
18) <processModel> System Allows configuration of ASP.NET process model settings.
19) <securityPolicy> Security Allows the mapping of defined security levels to policy files.
20) <sessionState> System Allows configuration of the session state HTTP module.
21) <trace> Application Allows configuration of the ASP.NET trace service
22) <trust> Security Allows configuration of the code access security permission set used to run our application.
23) <webRequestModules> System Allows configuration of ASP.NET's use of modules for request processing based on the prefix.
24) <webServices> System Allows configuration of ASP.NET Web Services settings

 After looking above tags these standard configuration tags into three main configuration groups:
 ■ ASP.NET Application Configuration
 ■ ASP.NET System Configuration
 ■ ASP.NET Security Configuration

logoblog

Thanks for reading asp.net Web.config

Previous
« Prev Post

No comments:

Post a Comment

Please do not enter any spam link in the comment box.