简体   繁体   中英

ApplicationPath vs “~”, which is better to find the application path?

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM