Partilhar via


Walkthrough: Configuring ASP.NET Applications using MMC 

ASP.NET enables you to make configuration settings for your application in a variety of ways, including the following:

  • With the Web Site Administration Tool, which is a tool that allows Web site owners to manage their Web sites either locally or remotely.

  • Using the Configuration API to manage settings programmatically.

  • Using the ASP.NET Microsoft Management Console (MMC). The MMC allows 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, the MMC gives you control over the entire configuration hierarchy for the Web server.

In this walkthrough, you will explore using the MMC. You will add an application setting to a single Web site that will store a value representing the background color of a Web page. You will then create an ASP.NET Web page that uses the application setting you are making. Although the task you accomplish with the 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:

  • Launching the ASP.NET MMC.

  • Making and changing settings in the MMC.

  • Viewing the results of configuration changes made with the MMC.

Prerequisites

In order to complete this walkthrough, you will need:

  • Microsoft Internet Information Services (IIS) 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

  1. On your computer, create a folder to hold the files for your Web site.

    For example, create a folder named C:\SampleWebSite.

  2. Click Start, and then click Run.

  3. In the Open box, type inetmgr, and then click OK.

  4. In Internet Information Services (IIS) Manager, expand the local computer, and then expand Web Sites.

  5. Right-click Default Web Site, point to New, and then click Virtual Directory.

    The Virtual Directory Creation Wizard appears.

  6. Click Next.

  7. In the Alias box, type a name for the site such as SampleWebSite, and then click Next.

  8. In the Path box, enter the path for the folder you created in step 1, and then click Next.

  9. 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

  1. 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.

  2. On the ASP.NET tab, click Edit configuration.

    The ASP.NET Configuration Settings dialog box appears.

  3. On the General tab, under Application Settings, click Add.

    The Edit/Add Application Settings dialog box appears.

  4. In the Key box, type CustomBGColor.

  5. In the Value box, type #00FF00, which is the hexadecimal color code for green.

  6. Click OK to close the Edit/Add Application Settings dialog box.

  7. Click OK to close the ASP.NET Configuration Settings dialog box.

  8. Click OK to close the <WebSiteName> Properties dialog box.

    NoteNote

    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

  1. 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, the MMC created a new Web.config file, because one did not exist before.

  2. Open the Web.config file in a text editor such as Notepad.

  3. 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>
    

    The 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 the MMC by creating a Web page that uses the setting.

To use the application setting

  1. 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.

  2. Copy the following code into the Default.aspx page.

    <%@ Page Language="VB" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://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="http://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"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">
        string CustomBGColor =
             ConfigurationManager.AppSettings["CustomBGColor"];
    </script>
    
    <html xmlns="http://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>
    
  3. Open the browser, and then enter the following URL:

    https://localhost/SampleWebSite/Default.aspx
    

    The page appears in the browser.

  4. 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

  1. In Internet Information Services (IIS) Manager, right-click the virtual directory, and then click Properties.

  2. On the ASP.NET tab, click Edit configuration.

  3. On the General tab, under Application Settings, click the row containing the CustomBGColor setting, and then click Edit.

  4. In the Value box, type #0000FF (the hexadecimal color code for blue).

  5. Click OK to close the Edit/Add Application Settings dialog box.

  6. Click OK to close the ASP.NET Configuration Settings dialog box.

  7. Click OK to close the <WebSiteName> Properties dialog box.

  8. Open the browser, and then enter the following URL:

    https://localhost/SampleWebSite/Default.aspx
    
  9. 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:

See Also

Other Resources

ASP.NET Configuration API
ASP.NET Web Site Administration Tool
ASP.NET Configuration Settings
Configuring ASP.NET Applications