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

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

You May Also Like

You can read connection string from web.config file in ASP.NET by using the ConfigurationManager class in case you want to...
When you deploy your ASP.NET Web Application on Windows Server running IIS , there are times that you might receive...
This post will explain how to resolve the error “Handler “aspNetCore” has a bad module “AspNetCoreModuleV2” in its module list”...