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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -