1
2
3var imagePath = "<%= (Server.MapPath(".")).Replace(@"\",@"\\") %>" + "/Images/UpLoad/";
2
3var imagePath = "<%= (Server.MapPath(".")).Replace(@"\",@"\\") %>" + "/Images/UpLoad/";
几种获取asp.net应用程序的路径:
1HttpContext.Current.Request.Url.Host//获取服务器的DNS主机名或IP地址
2
3HttpContext.Current.Request.ApplicationPath//ASP.NET应用程序的虚拟应用程序根路径
4
5/// <summary>
6 /// ASP.NET应用程序的根URL
7 /// </summary>
8 public string UrlBase
9 {
10 get
11 {
12 return @"http://" + UrlSuffix;
13 }
14 }
15
16private string UrlSuffix
17 {
18 get
19 {
20 return HttpContext.Current.Request.Url.Host + HttpContext.Current.Request.ApplicationPath;
21 }
22 }
23
24HttpContext.Current.Request.PhysicalApplicationPath//应用程序的根目录的物理路径
2
3HttpContext.Current.Request.ApplicationPath//ASP.NET应用程序的虚拟应用程序根路径
4
5/// <summary>
6 /// ASP.NET应用程序的根URL
7 /// </summary>
8 public string UrlBase
9 {
10 get
11 {
12 return @"http://" + UrlSuffix;
13 }
14 }
15
16private string UrlSuffix
17 {
18 get
19 {
20 return HttpContext.Current.Request.Url.Host + HttpContext.Current.Request.ApplicationPath;
21 }
22 }
23
24HttpContext.Current.Request.PhysicalApplicationPath//应用程序的根目录的物理路径