Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 213
Guy Dubrovski Avatar asked Oct 16 '25 01:10

Guy Dubrovski


1 Answers

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

HttpContext.Current.Server.MapPath("~/") 
like image 185
Max Al Farakh Avatar answered Oct 18 '25 15:10

Max Al Farakh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!