Since Microsoft Web API isn't MVC, you cannot do something like this:
var a = Request.MapPath("~");
nor this
var b = Server.MapPath("~");
because these are under the System.Web
namespace, not the System.Web.Http
namespace.
So how do you figure out the relative server path in Web API ?
I used to do something like this in MVC:
var myFile = Request.MapPath("~/Content/pics/" + filename);
Which would give me the absolute path on disk:
"C:inetpubwwwrootmyWebFolderContentpicsmypic.jpg"
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…