Walkthrough: Configuring ASP.NET Applications in IIS 6.0 using MMC
ASP.NET enables you to make configuration settings for applications that are running in Internet Information Services (IIS) 6.0. You can make configuration settings in the following ways:
With the Web Site Administration Tool, lets Web site owners manage Web sites either locally or remotely. For more information, see ASP.NET Web Site Administration Tool.
By using the configuration API to manage settings programmatically. For more information, see ASP.NET Configuration API Overview.
By using the ASP.NET Microsoft Management Console (MMC). MMC enables an administrator on the server to make configuration settings for all Web sites or for a specific Web site. Unlike the Web Site Administration Tool, MMC gives you control over the complete configuration hierarchy for the Web server.
In this walkthrough, you will explore MMC. You will add an application setting to a single Web site that will store a value that represents the background color of a Web page. You will then create an ASP.NET Web page that uses the application setting that you are making. Although the task that you accomplish with MMC in this walkthrough is not complex, it serves as an introduction to how to work with the ASP.NET MMC.
Tasks illustrated in this walkthrough include the following:
Launching the ASP.NET MMC.
Making settings in MMC.
Viewing the results of configuration changes that you made with MMC.
For information about how to configure IIS by using IIS Manager, see Configuring Internet Sites and Services (IIS 6.0).
Note
When you use the IIS MMC snap-in to configure a remote server, the ASP.NET Configuration Settings dialog box is not available.
Prerequisites
In order to complete this walkthrough, you will need:
Microsoft Internet Information Services (IIS) 6.0 installed locally on your computer.
The .NET Framework version 2.0.
Administrative privileges on your computer.
Creating an IIS Virtual Directory
In the first part of the walkthrough, you will create a folder for your Web pages and use Internet Information Services (IIS) Manager to create a virtual directory to which it points.
To create a folder and IIS virtual directory
On your computer, create a folder to hold the files for your Web site.
For example, create a folder named C:\SampleWebSite.
Click Start, and then click Run.
In the Open box, type inetmgr, and then click OK.
In Internet Information Services (IIS) Manager, expand the local computer, and then expand Web Sites.
Right-click Default Web Site, point to New, and then click Virtual Directory.
The Virtual Directory Creation Wizard appears.
Click Next.
In the Alias box, type a name for the site such as SampleWebSite, and then click Next.
In the Path box, enter the path for the folder you created in step 1, and then click Next.
Select the Read and Run scripts check boxes, click Next, and then click Finish.
Using the ASP.NET MMC to Make Application Settings
You can now use the ASP.NET MMC to make settings for the Web site.
To create the application setting
In Internet Information Services (IIS) Manager, right-click the name of your new virtual directory, and then click Properties.
The <WebSiteName> Properties dialog box appears.
On the ASP.NET tab, click Edit configuration.
The ASP.NET Configuration Settings dialog box appears.
On the General tab, under Application Settings, click Add.
The Edit/Add Application Settings dialog box appears.
In the Key box, type CustomBGColor.
In the Value box, type #00FF00, which is the hexadecimal color code for green.
Click OK to close the Edit/Add Application Settings dialog box.
Click OK to close the ASP.NET Configuration Settings dialog box.
Click OK to close the <WebSiteName> Properties dialog box.
Note
Leave the Internet Information Services (IIS) Manager open.
The ASP.NET MMC is a graphical tool for editing ASP.NET configuration files. In this walkthrough, you are editing configuration settings for a single Web application, meaning that you are editing the Web.config file for the Web site that you created at the beginning of the walkthrough. You will now verify the setting that you have made in the ASP.NET MMC by examining the Web.config file.
To verify the application setting
In Windows Explorer, navigate to the folder that you created at the beginning of the walkthrough.
The folder now contains a Web.config file. When you created configuration settings for the Web site, MMC created a new Web.config file, because one did not exist before.
Open the Web.config file in a text editor such as Notepad.
Verify that the following element was created in the Web.config file:
<?xml version="1.0" encoding="utf-8"?> <configuration> <appSettings> <add key="CustomBGColor" value="#00ff00" /> </appSettings> </configuration>
MMC created the <appSettings> element to hold the key/value pair that you defined.
Using the Application Setting
You can now test the application setting you created with MMC by creating a Web page that uses the setting.
To use the application setting
In the folder that you created at the beginning of the walkthrough, create a new text file and name it Default.aspx.
You can edit the file using any text editor, such as Notepad.
Copy the following code into the Default.aspx page.
<%@ Page Language="VB" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> Protected Function CustomBGColor() As String Return ConfigurationManager.AppSettings("CustomBGColor") End Function </script> <html xmlns="https://www.w3.org/1999/xhtml" > <head> <title>Sample Web Application</title> </head> <body style="background-color:<%=CustomBGColor%>"> <form runat="server" id="Form1"> Body background color: <%=CustomBGColor%> </form> </body> </html>
<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> string CustomBGColor = ConfigurationManager.AppSettings["CustomBGColor"]; </script> <html xmlns="https://www.w3.org/1999/xhtml" > <head> <title>Sample Web Application</title> </head> <body style="background-color:<%=CustomBGColor%>"> <form runat="server" id="Form1"> Body background color: <%=CustomBGColor%> </form> </body> </html>
Open the browser, and then enter the following URL:
https://localhost/SampleWebSite/Default.aspx
The page appears in the browser.
Verify that the background color is green.
Changing Settings in the ASP.NET MMC
You can use the ASP.NET MMC to change existing settings as well.
To change the background color
In Internet Information Services (IIS) Manager, right-click the virtual directory, and then click Properties.
On the ASP.NET tab, click Edit configuration.
On the General tab, under Application Settings, click the row containing the CustomBGColor setting, and then click Edit.
In the Value box, type #0000FF (the hexadecimal color code for blue).
Click OK to close the Edit/Add Application Settings dialog box.
Click OK to close the ASP.NET Configuration Settings dialog box.
Click OK to close the <WebSiteName> Properties dialog box.
Open the browser, and then enter the following URL:
https://localhost/SampleWebSite/Default.aspx
Verify that the background color is blue.
Next Steps
This walkthrough has provided you with an introduction to the ASP.NET MMC, which allows you to make ASP.NET configuration settings as an administrator on the Web server computer. You might also want to explore additional ways to work with ASP.NET configuration settings. Suggestions for more exploration include:
Use the Web Site Administration Tool to make configuration settings for a single Web site. For more information, see ASP.NET Web Site Administration Tool.
Use the Configuration APIs to change configuration settings programmatically. For more information, see ASP.NET Configuration API.
See Also
Other Resources
ASP.NET Web Site Administration Tool