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 或相对于根的 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.

适用于