Control.MapPathSecure(String) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
擷取虛擬絕對路徑或相對路徑所對應至的實體路徑。
protected:
System::String ^ MapPathSecure(System::String ^ virtualPath);
protected public:
System::String ^ MapPathSecure(System::String ^ virtualPath);
protected string MapPathSecure (string virtualPath);
protected internal string MapPathSecure (string virtualPath);
member this.MapPathSecure : string -> string
Protected Function MapPathSecure (virtualPath As String) As String
Protected Friend Function MapPathSecure (virtualPath As String) As String
參數
- virtualPath
- String
相對的或根相對路徑的 URL。
傳回
所要求檔案的實體路徑。
例外狀況
virtualPath
為 null
或空字串 ("")。
範例
下列範例會 MapPathSecure 使用 方法來取得包含 Page 或 UserControl 物件的虛擬目錄實體路徑。
// 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。 這有助於防止安全性缺口。