asp.net web api - Microsoft Web API: How do you do a Server.MapPath? -
since microsoft web api isn't mvc, cannot this:
var = request.mappath("~");
nor this
var b = server.mappath("~");
because these under system.web
namespace, not system.web.http
namespace.
so how figure out relative server path in web api ?
used in mvc:
var myfile = request.mappath("~/content/pics/" + filename);
which give me absolute path on disk:
"c:\inetpub\wwwroot\mywebfolder\content\pics\mypic.jpg"
you can use hostingenvironment.mappath in context system.web
objects httpcontext.current
not available (e.g static method).
var mappedpath = system.web.hosting.hostingenvironment.mappath("~/somepath");
see what difference between server.mappath , hostingenvironment.mappath?
Comments
Post a Comment