共用方式為


Application.Path 屬性

定義

取得或設定與應用程式相關聯的相對。

public:
 property System::String ^ Path { System::String ^ get(); void set(System::String ^ value); };
public string Path { get; set; }
member this.Path : string with get, set
Public Property Path As String

屬性值

應用程式所系結的相對路徑。

範例

下列範例會顯示預設網站下所設定之應用程式的相對路徑。

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

namespace AdministrationSnippets
{
    public class AdministrationApplicationPath
    {
// Writes out the application paths found under the default Web site.
public void GetPath()
{
    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);
    }
}
    }
}

下列範例會建立新的應用程式,然後使用 Path 屬性來變更應用程式的相對路徑,然後使用 PhysicalPath 屬性來變更應用程式的實體路徑。

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

namespace AdministrationSnippets
{
    public class AdministrationApplicationPath
    {
// Creates an application and sets its associated path. 
public void SetPath()
{
    // Create a new application.
    ServerManager manager = new ServerManager();
    Site defaultSite = manager.Sites["Default Web Site"];
    defaultSite.Applications.Add("/blogs1", @"C:\inetpub\wwwroot\");
    manager.CommitChanges();

    // Change the relative path.
    manager = new ServerManager();
    defaultSite = manager.Sites["Default Web Site"];
    defaultSite.Applications["/blogs1"].Path = @"/blogs2";
    manager.CommitChanges();

    // Change the physical path.
    manager = new ServerManager();
    defaultSite = manager.Sites["Default Web Site"];
    defaultSite.Applications["/blogs2"].VirtualDirectories["/"].PhysicalPath
        = @"C:\inetpub\wwwroot\blogs";
    manager.CommitChanges();
}
    }
}

備註

這個值代表應用程式根目錄的路徑。

適用於