I want to use Server.MapPath() method im order to map a virtual directory I created to its physical path.
The thing is that the .net environment doesn\'t recognize S
Make sure you have included System.Web in your projects References Do these (In Visual Studio IDE):
Server.MapPath should now be available.
Same problem here. In an ASP.net 4.0 web application, in a .ashx handler, with a using System.Web
at the top. I couldn't use Server.MapPath()
which is what the book I have says to use or System.Web.HttpServerUtility.MapPath()
which is what Google and MSDN keep turning up. I also couldn't use HttpServerUtility.MapPath()
as mentioned above.
However, one of the other answers here prompted me to try context.Server.MapPath()
which does work in my ProcessRequest(HttpContext context)
method.
If you have a web application, you should automatically have a reference to System.Web.dll
, and you should have access to the System.Web.HttpContext
class. Check that you haven't accidentally removed the reference. You would need a using System.Web;
statement to access the HttpContext
class without specifying the complete namespace.
If you don't have a web application you would have to add a referece to System.Web.dll
to get access to the HttpContext
class, but that would not help you a bit. As you are not in a web application, there is no HTTP context and there is no web root folder, so you can not use the MapPath method.