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

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Hey, wait!Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

You cannot copy content of this page