Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Control.MapPathSecure Method

Retrieves the physical path that a virtual path, either absolute or relative, maps to.

[Visual Basic]
Protected Function MapPathSecure( _
   ByVal virtualPath As String _
) As String
[C#]
protected string MapPathSecure(
 string virtualPath
);
[C++]
protected: String* MapPathSecure(
 String* virtualPath
);
[JScript]
protected function MapPathSecure(
   virtualPath : String
) : String;

Parameters

virtualPath
A relative or root relative URL.

Return Value

The physical path to the requested file.

Exceptions

Exception Type Condition
HttpException Occurs when the server control does not have permissions to read the resulting mapped file.

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.

Example

[Visual Basic, C#, C++] The following example uses the MapPathSecure method to obtain the physical path of a virtual directory of the containing Page or UserControl object.

[Visual Basic] 
' 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

[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>");

[C++] 
// An HttpException occurs if the server control does not
// have permissions to read the resulting mapped file.
     output->Write(S"The Actual Path of the virtual directory : {0}<br>", MapPathSecure(TemplateSourceDirectory));

    // 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(S"The files in this Directory are <br>");

         // List all the files.
         for (int i=0;i<myFiles->Length;i++)
            output->Write(S"{0}<br>", myFiles[i]);

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

Control Class | Control Members | System.Web.UI Namespace

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.