ASP.NET

ASP.NET MMC Snap-in

If your site is running from within a virtual directory (through IIS), you may use the ASP.NET Snap-in (available through the Microsoft Management Console, or MMC) to edit configuration information. To use this, you need to have your site managed by IIS.

While the Snap-in is only available on the computer hosting the site, it is much more extensive in its ability to manage your ASP.NET application.

Here's an exercise to familiarize yourself with the ASP.NET MMC Snap-in.

Use the MMC Snap-in

  1. Begin by creating a new Web site. Call it ConfigORamaIIS. Make it an HTTP site managed by IIS (that is, select HTTP in the Location combo box on the page). Run it from your own computer (localhost). Visual Studio will create a virtual directory for you and point itself to the virtual directory.

    Graphic
  2. Open up IIS. Look for the ConfigORamaIIS site:

    Graphic
  3. Right-click on the virtual directory node to get to the Properties. Select the ASP.NET tab.

    Graphic
  4. Click the Edit Configuration button to get to the configuration editor.

    Graphic

    The first tab in the Configuration Settings dialog box is the General tab. Notice there is a Connection string manager section (with a default connection string) and an Application settings section. Click the Add button underneath the Application settings window. Here's where you may add application settings-just as you did with the ASP.NET Configuration tool. Clicking the Add button brings up the Edit/Add Application Settings editor. Add a key-value pair.

    Graphic
  5. Open Web.Config within your application. It should now include an entry for AnotherString.

    <?xml version="1.0" encoding="utf-8"?>
    <configuration
    xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
        <appSettings>
            <add key="AnotherString" value="AnotherValue" />
        </appSettings>
    </configuration>
    
  6. Add a setting named BackgroundColor. Give it a value of #00FF. This will expose a setting that administrators can use to change the background color of Default.aspx (after support is built into the code).

    Graphic
  7. Now add a method to the Default page (Default.aspx.cs) to retrieve the background color. It should be available from the ConfigurationManager.AppSettings collection.

    public partial class _Default : System.Web.UI.Page
    {
       protected String BackgroundColor()
    {
         return
           ConfigurationManager.AppSettings["BackgroundColor"];
    }
    
    protected void Page_Load(object sender, EventArgs e)
        {
        }
    }
    
  8. Open the Default.aspx page to the Source view and update the body tag to retrieve the background color from the Application Settings. Use the <% and %> braces to mark executable code. Also add a line to the ASPX file to display background color value.

    <%@ Page Language="C#" AutoEventWireup="true"
    CodeFile="Default.aspx.cs" Inherits="_Default" %>
    <!DOCTYPE html PUBLIC
    "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body bgcolor="<%=BackgroundColor()%>">
        Body background color: <%=BackgroundColor()%>
        <form id="form1" runat="server">
        <div>
        </div>
        </form>
    </body>
    </html>
    
  9. Compile the program and run the page. The value #00FF translates to a bright green, so the background for your page should now appear bright green.

  10. Browse through some of the other tabs in the ASP.NET Configuration Settings dialog box available through IIS. We'll encounter many of these settings as we go through ASP.NET.

    • The Custom Errors page allows you to specify specific pages to which ASP.NET will redirect clients when the application throws an exception.

    • The Authentication tab is for setting up users and assigning them roles within your application.

    • The Authentication tab is also for specifying what type of authentication ASP.NET should apply to your site.

    • The Application tab manages such issues as localization and themes/master pages.

    • The State management tab is for managing session state. You can tell ASP.NET to store session state in any of a number of places, including in process on the host machine, out of process using a dedicated state server, or on a dedicated SQL Server database.

    • The Location tab manages specific settings for specific resources.

The configuration story doesn't end here. ASP.NET relies on Web.Config for almost all of its settings. While we touched on only a couple of settings in this tutorial, we'll see most of them throughout the next tutorials. We'll revisit configuration when covering features such as security, session state, error messages, and HttpHandlers/HttpModules.