Many settings that control the behavior of an ASP.NET application are found in its web.config file, a special XML document that's placed in the virtual directory of a web application. In the past, ASP.NET developers were forced to edit the web.config settings by hand. But your life is about to get simpler thanks to a new ASP.NET 2.0 graphical interface called the Web Site Administration Tool (WAT).
Note
Thanks to the new Web Site Administration Tool, there's no need to edit the web.config configuration file by hand.
The Web Site Administration Tool (WAT) is installed on your computer with the .NET Framework 2.0. It allows you to configure ASP.NET web application settings using a dedicated web page.
To run the WAT to configure the current web project in Visual Studio, select Website → ASP.NET Configuration. Internet Explorer will automatically log you on under the current user account. Try it. Figure 4-3 shows you the screen you'll see.
To try out WAT, click the Application tab and then click the "Create application settings" link. A pair of text boxes will appear that allow you to define the name and value of a new setting (see Figure 4-4). Enter "AppName" and "My Test ASP.NET Application" respectively, and click Save.
Now, open the web.config
file to see the result. You'll find a new <appSettings>
section with the
following setting defined:
<appSettings> <add key="AppName" value="My Test ASP.NET Application" /> </appSettings>
This illustrates the basic way that WAT works—you interact with a web page, and it generates the settings you need behind the scenes. To edit or remove this setting, you simply need to return to the WAT and select the "Manage application settings" link.
If you want, you can complete this example by writing a simple
routine to display the application setting in your page. Just add a
label control to your web page and insert the following code in the
Page_Load( )
event handler:
Label1.Text = "You are running " & _ ConfigurationSettings.AppSettings("AppName")
Of course, using the WAT to generate application settings is only the beginning. You can also use the WAT to perform the following tasks:
- Security
Use this tab to set the authentication mode, define authorization rules, and manage users. You'll learn about this tab in the upcoming lab "Easily Authenticate Users."
- Application
Use this tab to set application settings (as demonstrated in this lab) and configure web site counters and debugging.
- Provider
Use this tab to configure where user role and personalization information is stored. By default, ASP.NET uses Access to store this information in the AspNetDB.mdb in the App_Data subdirectory (in Beta 1) or in a SQL Server database (in Beta 2).
...making changes to the configuration settings of a web
application programmatically? Impressively, ASP.NET includes an
extensive set of classes for exactly this purpose in the System.Web.Configuration
and System.Web.Administration
namespaces. You
can use these classes to retrieve or alter web application settings in
your web page or web service code. In fact, the entire Web Site
Administration Tool is written as an ASP.NET application, and you'll
find the source code (in C#) in the following directory:
c:\[Windows Directory]\Microsoft.NET\Framework\[Version]\ ASP.NETWebAdminFiles
Get Visual Basic 2005: A Developer's Notebook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.