Is it possible to get the current hostname from the controller constructor?
Both the Request and HttpContext objects are null, so Request.Url yields nothing.
public class HomeController : Controller
{
private readonly MyEntities _entities;
public HomeController()
{
//
var hostname = Request.Url;
if (hostname.Contains("localhost")) EFConnectionStringName="localhost";
else EFConnectionStringName="default";
_entities = new MyEntities(EFConnectionStringName);
}
...
The greater problem I am trying to solve here is to choose a connection string for Entity Framework based upon the hostname. Ideas?