làm thế nào để lấy đường dẫn ứng dụng? đường dẫn thùng rác
trong asp.net
cảm ơn trước
làm thế nào để lấy đường dẫn ứng dụng? đường dẫn thùng rác
trong asp.net
cảm ơn trước
Lấy đường dẫn gốc ứng dụng ảo của ứng dụng ASP.NET trên máy chủ.
Request.ApplicationPath;
http://msdn.microsoft.com/en-us/library/system.web.httprequest.applicationpath.aspx
ResolveUrl("~/bin");
Server.MapPath("~/bin")
Bạn cũng có thể sử dụng thuộc tính HostingEnosystem.ApplicationPhysicalPath .
Tôi cần điều này ở app_start
nơi chưa có HttpContext
, do đó Request
và Server
không phải là lựa chọn.
Điều này đã thực hiện thủ thuật:
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;
}
}
và nhiều hơn nữa được mô tả trong blog
Sử dụng đoạn mã sau:
string strPath = HttpContext.Current.Server.MapPath("~/bin");
Server.MapPath("~/bin")
Bạn cũng có thể dùng Request.PhysicalApplicationPath
HostingEnvironment.MapPath()
Vs Server.MapPath()
Server.MapPath được sử dụng để lập bản đồ vị trí thực trên máy chủ web cho asp.net. String path = HttpContext.Current.Server.MapPath("~/myFolder/myFile.txt");
Server.MapPath chỉ định đường dẫn tương đối hoặc đường dẫn ảo để ánh xạ tới một thư mục vật lý.
mẫu vật:
string path=System.Web.Hosting.HostingEnvironment.MapPath(@"~/Files/ExamResult.rdlc");
Để biết thêm chi tiết, hãy truy cập liên kết này