如何获取应用程序路径? bin路径
在asp.net中
提前致谢
获取ASP.NET应用程序在服务器上的虚拟应用程序根路径。
Request.ApplicationPath;
http://msdn.microsoft.com/en-us/library/system.web.httprequest.applicationpath.aspx
ResolveUrl("~/bin");
Server.MapPath("~/bin")
我需要这个在app_start
,那里还没有HttpContext
,因此Request
和Server
不是选项。
这样就可以了:
System.Web.HttpRuntime.BinDirectory
HttpContext.Current.Server.MapPath("~/bin") ;
Application.StartupPath + "/bin";
AppDomain.CurrentDomain.BaseDirectory + "/bin";
//Note in Asp.net Core its little bit different
public class ValuesController : ControllerBase
{
IHostingEnvironment _hostingEnvironment;
public ValuesController(IHostingEnvironment hostingEnvironment)
{
_hostingEnvironment = hostingEnvironment;
string applicationPath = _hostingEnvironment.ContentRootPath;
string wwwrootPath = _hostingEnvironment.WebRootPath;
}
}
以及在blog中描述的更多内容
使用以下代码段:
string strPath = HttpContext.Current.Server.MapPath("~/bin");
Server.MapPath("~/bin")
你也可以使用Request.PhysicalApplicationPath
HostingEnvironment.MapPath()
与Server.MapPath()
Server.MapPath用于在webserver上为asp.net映射物理位置。 String path = HttpContext.Current.Server.MapPath("~/myFolder/myFile.txt");
Server.MapPath指定映射到物理目录的相对或虚拟路径。
样品:
string path=System.Web.Hosting.HostingEnvironment.MapPath(@"~/Files/ExamResult.rdlc");
详情请访问此Link