4.2. Administer a Web ApplicationMany 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. 4.2.1. How do I do that?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. Figure 4-3. The Web Site Administration ToolTo 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. Figure 4-4. Configuring an application's setting through WATNow, 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 worksyou 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:
4.2.2. What about......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 4.2.3. Where can I learn more?To learn more about the WAT, look for the index entry "Web Site Administration Tool" in the MSDN Help. |