Changeset 9

Show
Ignore:
Timestamp:
11/30/06 12:08:56 (2 years ago)
Author:
anonymous
Message:

added url methods

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Website/App_Code/Utility.cs

    r3 r9  
    1616/// </summary> 
    1717public class Utility 
    18 {   
     18
     19 
     20    public static string GetSiteUrl(string url) 
     21    { 
     22        if (String.IsNullOrEmpty(url)) 
     23        { 
     24            return GetSiteRoot() + "/"; 
     25        } 
     26        if (url.StartsWith("~/")) 
     27        { 
     28            url = url.Substring(1, url.Length - 1); 
     29        } 
     30        return GetSiteRoot() + url; 
     31    } 
     32 
     33    public static string GetUrlPath(string url) 
     34    { 
     35        return HttpContext.Current.Request.MapPath(url); 
     36    } 
     37 
     38    public static string GetRelativeSiteUrl(string url) 
     39    { 
     40        if (!String.IsNullOrEmpty(url)) 
     41        { 
     42            if (url.StartsWith("~/")) 
     43            { 
     44                url = url.Substring(1, url.Length - 1); 
     45            } 
     46            return GetRelativeSiteRoot() + url; 
     47        } 
     48        return GetRelativeSiteRoot() + "/"; 
     49    } 
     50 
     51    public static string GetSiteRoot() 
     52    { 
     53        string Port = HttpContext.Current.Request.ServerVariables["SERVER_PORT"]; 
     54        if (Port == null || Port == "80" || Port == "443") 
     55            Port = ""; 
     56        else 
     57            Port = ":" + Port; 
     58 
     59        string Protocol = HttpContext.Current.Request.ServerVariables["SERVER_PORT_SECURE"]; 
     60        if (Protocol == null || Protocol == "0") 
     61            Protocol = "http://"; 
     62        else 
     63            Protocol = "https://"; 
     64 
     65        string sOut = Protocol + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + Port + HttpContext.Current.Request.ApplicationPath; 
     66        return sOut; 
     67    } 
     68 
     69    public static string GetRelativeSiteRoot() 
     70    { 
     71        return HttpContext.Current.Request.ApplicationPath; 
     72    } 
    1973     
    2074    public static ILogger GetLogger(Type type)