共用方式為


Site.ApplicationDefaults 屬性

定義

取得目前網站下所設定之應用程式的預設值。

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

屬性值

ApplicationDefaults物件,表示為此網站所設定之應用程式的已設定預設值。

範例

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

namespace AdministrationSnippets
{
    public class AdministrationApplicationDefaults
    {
// Displays the default application values for all configured sites.
public void GetApplicationDefaults()
{
    ServerManager manager = new ServerManager();
    foreach (Site s in manager.Sites)
    {
        ApplicationDefaults d = s.ApplicationDefaults;
        Console.WriteLine("Site: {0}", s.Name);
        Console.WriteLine("  |--Default Application Pool:  {0}", 
            d.ApplicationPoolName);
        Console.WriteLine("  +--Default Protocols Enabled: {0}\r\n", 
            d.EnabledProtocols);
    }

}
// Sets the default values for applications configured under the 
// default Web site.
public void SetApplicationDefaults()
{
    ServerManager manager = new ServerManager();
    Site defaultSite = manager.Sites["Default Web Site"];
    ApplicationDefaults defaultVals = defaultSite.ApplicationDefaults;

    // Set the application defaults.
    defaultVals.ApplicationPoolName = "CommunitySites";
    defaultVals.EnabledProtocols = "http";
    
    // Create a new application.
    defaultSite.Applications.Add(
        "/discussion", @"C:\inetpub\wwwroot\forums");
    manager.CommitChanges();

    // Read the application's values.
    Application discussion = defaultSite.Applications["/discussion"];
    Console.WriteLine("Site: {0}", defaultSite.Name);
    Console.WriteLine("  |--Default Application Pool:  {0}", 
        discussion.ApplicationPoolName);
    Console.WriteLine("  +--Default Protocols Enabled: {0}\r\n", 
        discussion.EnabledProtocols);
}
    }
}

備註

ApplicationDefaults如果未明確設定值,物件代表 IIS 將推斷的應用程式組態值。 這些值不會在物件模型中表示,直到使用 Microsoft.Web.Administration.ServerManager.CommitChanges 方法寫入組態系統,然後再讀取。

適用於