private static SystemInfo loadSystemInfo() { SystemInfo obj = new SystemInfo(); if (IsWeb) { obj.applicationPath = HttpContext.Current.Request.ApplicationPath; obj.rootPath = addEndSlash( obj.applicationPath ); obj.authority = HttpContext.Current.Request.Url.Authority; obj.host = HttpContext.Current.Request.Url.Host; obj.hostIsLocalhost = strUtil.EqualsIgnoreCase( obj.host, "localhost" ); try { Convert.ToInt32(obj.host.Split('.')[0]); obj.hostIsIp = true; } catch { obj.hostIsIp = false; } obj.hostNoSubdomain = getHostNoSubdomain( obj ); } else { obj.applicationPath = "/"; obj.rootPath = "/"; obj.host = "localhost"; } return obj; }
private static String getHostNoSubdomain( SystemInfo obj ) { if (obj.hostIsIp || obj.hostIsLocalhost) { return obj.host; } else { return getHostNoSubdomain( obj.host ); } }