Advertisement
rjester

GetSiteRoot

Sep 25th, 2015
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static string GetSiteRoot()
  2. {
  3.     var port = HttpContext.Current.Request.Url.Authority;
  4.     var protocol = HttpContext.Current.Request.Url.Scheme;
  5.     var sOut = protocol + "://" + port + "/" + HttpContext.Current.Request.ApplicationPath;
  6.  
  7.     if (sOut.EndsWith("/"))
  8.         sOut = sOut.Substring(0, sOut.Length - 1);
  9.  
  10.     var sOut = protocol + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + port +
  11.                 HttpContext.Current.Request.ApplicationPath;
  12.  
  13.     if (sOut.EndsWith("/"))
  14.     {
  15.         sOut = sOut.Substring(0, sOut.Length - 1);
  16.     }
  17.  
  18.     return sOut;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement