HttpServerUtility.MapPath Method
.NET Framework 4
Returns the physical file path that corresponds to the specified virtual path on the Web server.
Assembly: System.Web (in System.Web.dll)
Parameters
- path
- Type: System.String
The virtual path of the Web server.
| Exception | Condition |
|---|---|
| HttpException |
The current HttpContext is null. |
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Throws HttpException when you traverse too high up
Server.MapPath(@"..\..\..\..\..\..\..\Whatever");
$0will throw System.Web.HttpException: Cannot use a leading .. to exit above the top directory.$0
- 1/24/2012
- Rob.Bittner
- 1/24/2012
- Rob.Bittner
Different Path Bits
See this article for a great explanation of the different types of paths you can map ("~/...", "/...", etc.):
http://stackoverflow.com/questions/275781/server-mappath-server-mappath-server-mappath-server-mappath
http://stackoverflow.com/questions/275781/server-mappath-server-mappath-server-mappath-server-mappath
- 6/2/2011
- AmosFiveSix
Security Note