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

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.
Pin It

Leave a Reply

Your email address will not be published. Required fields are marked *