How can I get my webapp’s base URL in ASP.NET MVC?

Assuming you have a Request object available, you can use:

string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Content("~"));

If it’s not available, you can get to it via the context:

var request = HttpContext.Current.Request

Leave a Comment