In MVC3, most directly, you can do it like this (it should be pretty accurate): Inside .cs, you can use code like this:
Uri uri = HttpContext.Current.Request.Url;
String absoluteUrlBase = String.Format(
"{0}://{1}{2}{3}"
uri.Scheme,
uri.Host,
(uri.IsDefaultPort
? ""
: String.Format(":{0}", uri.Port));
inside a.cshtml you can use
string absoluteUrlBase = String.Format(
"{0}://{1}{2}{3}"
Request.Url.Scheme
Request.Url.Host +
(Request.Url.IsDefaultPort
? ""
: String.Format(":{0}", Request.Url.Port));
In both cases there absoluteUrlBasewill be http://localhost:8512or http://www.contoso.com.
or you can follow the link VoodooChild ...