Share via


Application.VirtualDirectoryDefaults Property

Definition

Gets the default values that are assigned to all virtual directories of the application.

public:
 property Microsoft::Web::Administration::VirtualDirectoryDefaults ^ VirtualDirectoryDefaults { Microsoft::Web::Administration::VirtualDirectoryDefaults ^ get(); };
public Microsoft.Web.Administration.VirtualDirectoryDefaults VirtualDirectoryDefaults { get; }
member this.VirtualDirectoryDefaults : Microsoft.Web.Administration.VirtualDirectoryDefaults
Public ReadOnly Property VirtualDirectoryDefaults As VirtualDirectoryDefaults

Property Value

A VirtualDirectoryDefaults object that represents the default values that are assigned to all newly created virtual directories of the application.

Examples

The following example returns a list of the virtual directory default values for the applications under the default Web site.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Web.Administration;
using Microsoft.Web.Management;

namespace AdministrationSnippets
{
    public class AdministrationApplicationVirtualDirectoryDefaults
    {
// Returns a list of the virtual directory defaults for all 
// applications under the default Web site.
public void GetVirtualDirectoryDefaults()
{
    ServerManager manager = new ServerManager();
    Site defaultSite = manager.Sites["Default Web Site"];
    foreach (Application app in defaultSite.Applications)
    {
        Console.WriteLine(
            "Found application with the following path: {0}", app.Path);
        Console.WriteLine("Virtual Directory Defaults:");
        if (app.VirtualDirectories.Count > 0)
        {
            Console.WriteLine("  Attributes");
            foreach (string prop in 
                app.VirtualDirectoryDefaults.RawAttributes.Keys)
            {
                Console.WriteLine("   |-{0}: {1}", prop.PadRight(20),
                    app.VirtualDirectoryDefaults.GetAttribute(prop).Value);
            }
        }
    }
}
    }
}

The following example creates a new application, sets the virtual directory defaults, creates two new virtual directories, and then displays the new virtual directory values.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Web.Administration;
using Microsoft.Web.Management;

namespace AdministrationSnippets
{
    public class AdministrationApplicationVirtualDirectoryDefaults
    {

// Creates a new application, sets the virtual directory  
// defaults, creates two new virtual directories, and then  
// displays the new virtual directory values.
public void SetVirtualDirectoryDefaults()
{
    ServerManager manager = new ServerManager();
    Site defaultSite = manager.Sites["Default Web Site"];

    // Set up the defaults for the default application of the 
    // default Web site.
    Application app = defaultSite.Applications.Add(
        "/JohnDoe", @"C:\inetpub\wwwroot\john");

    app.VirtualDirectoryDefaults.LogonMethod = 
        AuthenticationLogonMethod.ClearText;
    app.VirtualDirectoryDefaults.UserName = @"NorthWest\JohnDoe";
    app.VirtualDirectoryDefaults.Password = @"kB56^j83!T";

    // Add two virtual directories.
    app.VirtualDirectories.Add(
        "/blogs" , @"\\FileServer\c$\blog_content\");
    app.VirtualDirectories.Add(
        "/photos", @"\\FileServer\c$\photo_content\");
    manager.CommitChanges();

    // Read the updated configuration.
    app = defaultSite.Applications["/JohnDoe"];

    foreach (VirtualDirectory vdir in app.VirtualDirectories)
    {
        Console.WriteLine("Virtual Directory Found: {0}", vdir.Path);
        Console.WriteLine("  |-Logon Method : {0}", vdir.LogonMethod);
        Console.WriteLine("  |-Username     : {0}", vdir.UserName);
        Console.WriteLine("  +-Password     : {0}", vdir.Password);
    }
}
    }
}

Remarks

Although the VirtualDirectoryDefaults property is read-only, the values in the collection returned allow for both reading and writing. After you change a value in the collection, you must use the CommitChanges method of a ServerManager object to write the values to the configuration system.

Applies to