Control.MapPathSecure(String) 方法

定义

检索虚拟路径(绝对的或相对的)映射到的物理路径。

C#
protected string MapPathSecure (string virtualPath);
C#
protected internal string MapPathSecure (string virtualPath);

参数

virtualPath
String

相对 URL 或相对于根的 URL。

返回

String

请求文件的物理路径。

例外

virtualPathnull 或空字符串 ("")。

示例

以下示例使用 MapPathSecure 该方法获取包含 PageUserControl 对象的虚拟目录的物理路径。

C#
// 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>");

注解

此方法只能由有权读取文件的服务器控件使用,这些控件属于完全受信任的.dll文件,例如System.Web.dll。 这有助于防止安全漏洞。

适用于

产品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8