To make it simpler for a webapp to share files with another app on a different server, I\'m using a base href tag in my master page. As many people have discovered, this breaks
I have used following and it worked for me both client and the server.
string surl = string.Format("{0}://{1}",
HttpContext.Current.Request.Url.Scheme,
HttpContext.Current.Request.Url.Authority);
Code :
string loginUrl = Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/") + "Login/Login.aspx?UserName=" + LoggedinUser["UserName"] + "&Password=" + LoggedinUser["Password"];
Old post but here is another slightly less verbose method
var baseUri = new Uri(HttpContext.Current.Request.Url, "/");
Using string interpolation:
string redirectUri = $"{this.Request.Url.Scheme}://{this.Request.Url.Authority}{this.Request.ApplicationPath}account/signedout";
Substitute 'this' for 'HttpContext' or 'HttpContext.Current' based on context.
I have used this in the past:
// Gets the base url in the following format:
// "http(s)://domain(:port)/AppPath"
HttpContext.Current.Request.Url.Scheme
+ "://"
+ HttpContext.Current.Request.Url.Authority
+ HttpContext.Current.Request.ApplicationPath;