Thursday, March 21, 2013

Get the root url from current page



 Current Page url: http://localhost:60602/index.aspx

string hostURL = HttpContext.Current.Request.Url.AbsoluteUri.Replace(HttpContext.Current.
Request.Url.AbsolutePath, "");

Output: http://localhost:60602


Get root url from WCF Service:


string rootURL = OperationContext.Current.Channel.LocalAddress.Uri.AbsoluteUri.
Replace(OperationContext.Current.Channel.LocalAddress.Uri.AbsolutePath, "");