..


Sponsored Links

The configuration files: machine.config and web.config

An important aspect of web applications is the management of configuration information, an area which includes several elements including:

  • Sessions were
  • Caching
  • Tracing
  • Authentication

These elements are controlled through a number of configurable parameters. For example, when an application you enable session state (session) you can determine where to place the management, given the choice between such a process or a separate computer (using Windows Service or SQL Server). It 'can also configure the length of the session state and the ways in which the application must keep track of such information (eg via cookies).

Although caching is a very important element because when you decide to cache the contents of its website this feature allows you to configure the duration of the stay in the cache and the location to be stored (on the server, the client, proxy).

The configuration options of these two features are managed through appropriate configuration files. In early versions of ASP.NET to change the configuration of a web application meant to operate directly on the configuration file in XML format. Fortunately however the latest versions of ASP.NET (from 2.0 onwards) provide two tools that make configuration much simpler web application. The first section is the ASP.NET Configuration tool available in IIS (version 7), the second is the Web Site Administration Tool in Visual Studio (see below).

Configuration files. NET are XML files with content that is understood by the runtime. NET Framework. At runtime these files are read for setting the various parameters required, and these parameters are cumulative. For example, the web.config configuration file is loaded when the application starts but the first configuration file that is examined is the machine.config and the settings of the two files are both followed.

The machine.config file is usually placed in C: \ Windows \ Microsoft.NET \ Framework \ vxxxxx \ Setup (where xxxxx is the version of. NET Framework). This file sets the default behavior of all. NET applications run on the local computer. Here's an example of this file

Note the presence of different configuration sections. Among the various example, you can find the following

indicating the execution environment using the ASP.NET Forms Authentication (one of the options available authentication) to authenticate users of the site. It also specifies to use SQL Server to manage session state, with a timeout of 25 minutes, and track that was directly in the URI.

The machine.config then allows you to manage the default settings of your computer and this has some effect on all. NET applications. For this reason it is not generally a good idea to make direct changes to the file. Alternatively applications windows form. NET also depend on a separate configuration file, and usually named the same as the executable (for example, if the executable is called miaapplicazione.exe the configuration file will be associated miaapplicazione.exe. config). Web applications. NET instead depend on a file called web.config. These files should be included in the folder where the application resides.

An example of the web.config file is as follows

In previous versions of ASP.NET 2.0 web.config files had to be changed manually without any tool support that would ensure that what you wrote to them was corretto.A from ASP.NET 2.0 but is available in Visual Studio a new tool called Web Site Administration Tool (WSAT).

Let us briefly see how it works. Create a new web project in Visual Studio or apriamone an existing (previously created ones are fine) and click on ASP.NET Configuration menu Website

This opens the following configuration page

through which you can modify the web.config file without having to write the code manually. We click on the tab, for example, Application and click on the link inside the Create Application Settings

Insert a setting called owner whose value is Goofy and save

If we look at the web.config we will see that the new setting is entered automatically

In a similar way you can configure security settings and other provider settings tab through the page.

Help with Visual Studio ASP.Net
E-Learning
ASP (Advanced) ASP (Advanced)
Full course for creating dynamic Web sites. From 39 €.
ASP.NET (Course) ASP.NET (Course)
Full course for building Web applications from 49 €.
SQL and Database (Course) SQL and Database (Course)
Create and manage relational databases. From 39 €.
Sponsored Links