.net WebApi - wrong value of HttpContext.Current.Server.MapPath

.net, asp.net-web-api, c#, visual-studio-2012

Solution

You probably need to add `~/` to get to the root folder. Like this:

HttpContext.Current.Server.MapPath("~/") 

Problem

I am using `HttpContext.Current.Server.MapPath` function in order to locate a resource in a site hosted by IIS. ``` HttpContext.Current.Server.MapPath("localPath") ``` The value that I get from it is: `c:\users\guy\documents\visual studio 2012\Projects\MyProject\MyProject\api\localPath` while the real content is in `C:\Users\guy\Documents\Visual Studio 2012\Projects\MyProject\MyProject\localPath` Why do I get an extra `api` in the end? maybe it has something to do with the fact I am running a webapi app? Thanks.

Original source