To get the absolute path use this:
String path = HttpContext.Current.Server.MapPath("~/Data/data.html");
EDIT:
To get the Controller's Context remove .Current
from the above line. By using HttpContext
by itself it's easier to Test because it's based on the Controller's Context therefore more localized.
I realize now that I dislike how Server.MapPath
works (internally eventually calls HostingEnvironment.MapPath
) So I now recommend to always use HostingEnvironment.MapPath
because its static and not dependent on the context unless of course you want that...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…