Last active
March 29, 2019 16:07
-
-
Save umair-me/0c7e6c8397df17e3a6a33cd0ebc0889e to your computer and use it in GitHub Desktop.
Get current domain url
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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