应用程序路径与“~”,最好找到应用程序路径
本文关键字:应用程序 路径 | 更新日期: 2023-09-27 18:35:45
我需要获取我的 ASP.NET-MVC-5-Application的基本/应用程序路径。
我找到了两个机会来获得它,并想知道什么是更好的选择:
UrlHelper.Content("~")
或
UrlHelper.RequestContext.HttpRequest.Request.ApplicationPath
使用这个,我认为这样更好
Server.MapPath("~/YourFolder/");
这里的"~"代表你的根文件夹
即。如果要从"内容"文件夹中获取" pic1.gif"文件
只需使用
string _path = Server.MapPath("~/Contents/");
string _myFile = "pic1.gif";
string _fullPath = _path + _myFile;