Control.MapPathSecure(String) Control.MapPathSecure(String) Control.MapPathSecure(String) Control.MapPathSecure(String) Method

定義

擷取虛擬絕對路徑或相對路徑所對應至的實體路徑。Retrieves the physical path that a virtual path, either absolute or relative, maps to.

protected public:
 System::String ^ MapPathSecure(System::String ^ virtualPath);
protected internal string MapPathSecure (string virtualPath);
member this.MapPathSecure : string -> string
Protected Friend Function MapPathSecure (virtualPath As String) As String

參數

virtualPath
String String String String

相對的或根相對路徑的 URL。A relative or root relative URL.

傳回

所要求檔案的實體路徑。The physical path to the requested file.

例外狀況

virtualPathnull 或空字串 ("")。virtualPath is null or an empty string ("").

範例

下列範例會使用MapPathSecure方法,以取得包含虛擬目錄的實體路徑PageUserControl物件。The following example uses the MapPathSecure method to obtain the physical path of a virtual directory of the containing Page or UserControl object.

// An HttpException occurs if the server control does not,;
// have permissions to read the resulting mapped file. 
     output.Write("The Actual Path of the virtual directory : "+
     MapPathSecure(TemplateSourceDirectory)+"<br>");

    // Get all the files from the absolute path of 'MyControl';
    // using TemplateSourceDirectory which gives the virtual Directory.
        string [] myFiles=
        Directory.GetFiles(MapPathSecure(TemplateSourceDirectory));
        output.Write("The files in this Directory are <br>");

         // List all the files.
         for (int i=0;i<myFiles.Length;i++)
            output.Write(myFiles[i]+"<br>");
' An HttpException occurs if the server control does not,;
' have permissions to read the resulting mapped file.
output.Write("The Actual Path of the virtual directory : " & _
            MapPathSecure(TemplateSourceDirectory) & "<br>")

' Get all the files from the absolute path of 'MyControl';
' using TemplateSourceDirectory which gives the virtual Directory.
Dim myFiles As String() = Directory.GetFiles(MapPathSecure(TemplateSourceDirectory))
output.Write("The files in this Directory are <br>")

' List all the files.
Dim i As Integer
For i = 0 To myFiles.Length - 1
   output.Write(myFiles(i) & "<br>")
Next i

備註

這個方法只用於具有讀取檔案的權限、 哪些是完全受信任的.dll 檔案,例如 System.Web.dll 一部分的伺服器控制項。This method can only be used by server controls that have permissions to read files and which are part of fully trusted .dll files, such as System.Web.dll. 這有助於防止安全性產生漏洞。This helps prevent security breaches.

適用於