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

Leave A Reply

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

You May Also Like

You can pass an array of integer to an ASP.NET Web Web API REST service by setting the [FromUri] attribute...
One of the common ways to refresh webpage every few mins is by using JavaScript or HTML Meta tag. For...
This post will provide the list of some of the top ASP.NET based Content Management Systems (CMS) that you may...