Fully qualified URLs with ASP.NET MVC

If you want to generate links in ASP.NET MVC you use the Url.Action or Html.ActionLink helpers. They will give you relative links to the controller action you are linking to.

What not everyone might know is that they can also be used to generate fully qualified URLs, e.g. “http://example.com/home/index” instead of “/home/index”.

You do this by specifying the protocol parameter to "http", or the dynamic value Request.Url.Scheme.

Url.Action:

@Url.Action("Index", "Home", routeValues: null, protocol: Request.Url.Scheme)

Html.ActionLink:

@Html.ActionLink("Home link", "Index", "Home", Request.Url.Scheme, null, null, routeValues:null, htmlAttributes: null)

published in ASP.NET MVC