I needed to get the Base-/Application-Path of my ASP.NET-MVC-5-Application.
I found two opportunities to get it and wonder what is the better choice:
UrlHelper.Content("~")
or
UrlHelper.RequestContext.HttpRequest.Request.ApplicationPath
Use this, i think this is better
Server.MapPath("~/YourFolder/");
here "~" represents your rootfolder
ie. If you want to get "pic1.gif" file from "Contents" folder
simply use
string _path = Server.MapPath("~/Contents/");
string _myFile = "pic1.gif";
string _fullPath = _path + _myFile;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.