Control.MapPathSecure(String) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Retrieves the physical path that a virtual path, either absolute or relative, maps to.
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
Parameters
- virtualPath
- String
A relative or root relative URL.
Returns
The physical path to the requested file.
Exceptions
virtualPath
is null
or an empty string ("").
Examples
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
Remarks
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.
Applies to
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기