共用方式為


Application.VirtualDirectoryDefaults 屬性

定義

取得指派給應用程式所有虛擬目錄的預設值。

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

屬性值

VirtualDirectoryDefaults物件,表示指派給應用程式所有新建立之虛擬目錄的預設值。

範例

下列範例會傳回預設網站下應用程式的虛擬目錄預設值清單。

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);
            }
        }
    }
}
    }
}

下列範例會建立新的應用程式、設定虛擬目錄預設值、建立兩個新的虛擬目錄,然後顯示新的虛擬目錄值。

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);
    }
}
    }
}

備註

VirtualDirectoryDefaults雖然屬性是唯讀的,但是傳回的集合中的值允許讀取和寫入。 變更集合中的值之後,您必須使用 CommitChanges 物件的 方法 ServerManager ,將值寫入組態系統。

適用於