Skip to content

Instantly share code, notes, and snippets.

@umair-me
Last active March 29, 2019 16:07
Show Gist options
  • Save umair-me/0c7e6c8397df17e3a6a33cd0ebc0889e to your computer and use it in GitHub Desktop.
Save umair-me/0c7e6c8397df17e3a6a33cd0ebc0889e to your computer and use it in GitHub Desktop.
Get current domain url
String strPathAndQuery = HttpContext.Current.Request.Url.PathAndQuery;
String strUrl = HttpContext.Current.Request.Url.AbsoluteUri.Replace(strPathAndQuery, "/");
// OR
Request.Url.GetLeftPart(UriPartial.Authority)
// https://stackoverflow.com/a/10337955/1158845
// OR
new Uri(_httpContextAccessor.HttpContext.Request.GetDisplayUrl()).GetComponents(UriComponents.SchemeAndServer, UriFormat.UriEscaped);
// https://stackoverflow.com/a/54815083
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment