Configuring .NET Applications

Once upon a time, configuration for applications was quite a pain. With desktop-based applications, you were often required to manipulate registry values or deal with external .ini files. These were both good places to store configuration information, but were lacking in flexibility.

The registry was a repository of application information, and a logical place to store your custom information. However, the registry was hardly portable, so settings on one machine were not transferable to another without a registry dump. Also, if anything occurred that caused your application to become out of sync with the registry (such as the application path changing), you were out of luck. For settings to be restored, you often had to simply reinstall the entire application.

.ini files were a bit more flexible, allowing you to move your settings with your applications. The problem with these files, however, was that the information contained within was very specific. It applied to only one application, and could not affect the operating system or other apps.

With ASP applications, configuration was an entirely different, and more unpleasant, issue. Settings had to be registered in IIS, and thus were not transferable. Configuring an application often required being physically located at the server. Many ASP developers will recall spending quite a bit of time at client sites setting up applications and servers. If anything ever needed to change, that meant another trip to the client site—a costly chore.

With VB .NET, developers have an entirely new way to configure their applications. The .NET Framework introduces the .config file, which allows you to customize all the settings you could ever want, from controlling where session state data is saved to custom database connection strings. This file is an XML file, and therefore can be easily transferred and deployed along with the rest of your application. No more writing registry values or manually configuring IIS—just make your changes using a simple text editor such as Notepad, save, and your settings take effect.

VB .NET applications use the name of the application for this file. For example, if your application is called Calculator, the corresponding configuration file will be called Calculator.config. It is stored in the same directory as the application, along with other application files. ASP.NET configuration files are always named web.config.

These files can contain all sorts of configuration information, and in the next few sections, you'll see how to use them in VB .NET and ASP.NET applications.

NOTE

.NET maintains a system-level config file that maintains default settings for all your applications and the CLR. This file is called machine.config, and is typically located in the c:winntMicrosoft.NETFrameworkversionConfig folder.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.219.67.169