How can I get the baseurl of site?
Try this:
string baseUrl = Request.Url.Scheme + "://" + Request.Url.Authority +
Request.ApplicationPath.TrimEnd('/') + "/";
The popular GetLeftPart
solution is not supported in the PCL version of Uri
, unfortunately. GetComponents
is, however, so if you need portability, this should do the trick:
uri.GetComponents(
UriComponents.SchemeAndServer | UriComponents.UserInfo, UriFormat.Unescaped);
string baseUrl = Request.Url.GetLeftPart(UriPartial.Authority)
That's it ;)