Control.MapPathSecure(String) 메서드

정의

가상 경로(절대 또는 상대)가 매핑되는 실제 경로를 가져옵니다.

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 또는 루트 상대 URL입니다.

반환

String

요청된 파일에 대한 실제 경로를 반환합니다.

예외

virtualPathnull 또는 빈 문자열("")인 경우

예제

다음 예제에서는 메서드를 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

설명

이 메서드는 파일을 읽을 수 있는 권한이 있고 System.Web.dll 같은 완전히 신뢰할 수 있는 .dll 파일의 일부인 서버 컨트롤에서만 사용할 수 있습니다. 이렇게 하면 보안 위반을 방지할 수 있습니다.

적용 대상