How to Get the Host Name of the Current URL in ASP.NET MVC ?

If you want to get the host name of the current URL from an action method in ASP.NET MVC project , you can use the Request.Url.Host property .

How to Get the Host Name of the Current URL in ASP.NET MVC ?

Below is a sample code snippet demonstrating how to get the host name of the current URL .

public ActionResult Index()
{
   string hostAddress = this.Request.Url.Host;
   return View();
}

image