asp.net mvc - Accessing a Virtual Directory from a Web API -
i have folder of files (form templates) need accessed both .net web api application , separate .net mvc application. folder these form templates outside of websites. ideally, i'd able store path in web.config files applications can tested in local environment.
i tried setting virtual directories on hosted site couldn't figure out how reference them in web api. tried several means of referencing virtual directory did not work. posts suggested trying server.mappath("myvirtualdirectory") returns "....\wwwroot\myapicontroller\action\myvirtualdirectory", not physical path of virtual directory.
i removed virtual directory , attempted "navigate" right path blocked "cannot utilize leading .. exit above top directory".
so right way access resource using virtual directory in .net web api application? same method going work .net mvc application?
you need utilize hostingenvironment
, like:
public static string mappath(string path){ string result; result = hostingenvironment.mappath(path); homecoming result; }
additionally hostingenvironment
provides features applicationphysicalpath
:
result = hostingenvironment.applicationphysicalpath + "app_data\\somefile.xml";
asp.net-mvc iis asp.net-web-api
No comments:
Post a Comment