温馨提示:代码在线浏览功能只能做为源码浏览参考,不能展示项目的全部,如果想更进一步了解该代码请下载:NETCMSv1.5(Build0509)完整源码版
当前文件路径:NetCMSv15/NetCMS.Common/ServerInfo.cs

1//====================================================== 2
//== (c)2008 aspxcms inc by NeTCMS v1.0 == 3
//== Forum:bbs.aspxcms.com == 4
//== Website:www.aspxcms.com == 5
//====================================================== 6
using System; 7
using System.Text; 8
using System.Text.RegularExpressions; 9
using System.Web; 10
11
namespace NetCMS.Common 12
{ 13
/// <summary> 14
/// WEB信息 15
/// </summary> 16
public class ServerInfo 17
{ 18
/// <summary> 19
/// 取得网站的根目录的URL 20
/// </summary> 21
/// <returns></returns> 22
public static string GetRootURI() 23
{ 24
string AppPath = ""; 25
HttpContext HttpCurrent = HttpContext.Current; 26
HttpRequest Req; 27
if (HttpCurrent != null) 28
{ 29
Req = HttpCurrent.Request; 30
31
string UrlAuthority = Req.Url.GetLeftPart(UriPartial.Authority); 32
if (Req.ApplicationPath == null || Req.ApplicationPath == "/") 33
//直接安装在 Web 站点 34
AppPath = UrlAuthority; 35
else 36
//安装在虚拟子目录下 37
AppPath = UrlAuthority + Req.ApplicationPath; 38
} 39
return AppPath; 40
} 41
/// <summary> 42
/// 取得网站的根目录的URL 43
/// </summary> 44
/// <param name="Req"></param> 45
/// <returns></returns> 46
public static string GetRootURI(HttpRequest Req) 47
{ 48
string AppPath = ""; 49
if(Req != null) 50
{ 51
string UrlAuthority = Req.Url.GetLeftPart(UriPartial.Authority); 52
if (Req.ApplicationPath == null || Req.ApplicationPath == "/") 53
//直接安装在 Web 站点 54
AppPath = UrlAuthority; 55
else 56
//安装在虚拟子目录下 57
AppPath = UrlAuthority + Req.ApplicationPath; 58
} 59
return AppPath; 60
} 61
/// <summary> 62
/// 取得网站根目录的物理路径 63
/// </summary> 64
/// <returns></returns> 65
public static string GetRootPath() 66
{ 67
string AppPath = ""; 68
HttpContext HttpCurrent = HttpContext.Current; 69
if (HttpCurrent != null) 70
{ 71
AppPath = HttpCurrent.Server.MapPath("~"); 72
} 73
else 74
{ 75
AppPath = AppDomain.CurrentDomain.BaseDirectory; 76
if (Regex.Match(AppPath, @"\\$", RegexOptions.Compiled).Success) 77
AppPath = AppPath.Substring(0, AppPath.Length - 1); 78
} 79
return AppPath; 80
} 81
} 82
} 83





}