0

I need to get the physical path of a file in a controller based on Web API.

I have seen that I can use

var context = Request.Properties["MS_HttpContext"] as HttpContext;

to get the context and then, by mean of the Server object, to use MapPath... however, MS_HttpContext is of type System.Web.HttpContextWrapper and when I cast to HttpContext, null is assigned to the variable.

Any hint about how to do this?

Regards Jaime

Maksym Labutin
  • 561
  • 1
  • 8
  • 17
jstuardo
  • 3,901
  • 14
  • 61
  • 136
  • 2
    Possible duplicate of [Microsoft Web API: How do you do a Server.MapPath?](https://stackoverflow.com/questions/16557122/microsoft-web-api-how-do-you-do-a-server-mappath) – Sonal Borkar Dec 03 '18 at 12:28

1 Answers1

1

Finally I have used System.Web.Hosting.HostingEnvironment.MapPath method call.

jstuardo
  • 3,901
  • 14
  • 61
  • 136