I'm serving my MVC app locally via localhost:5252 right now.
I'm trying to set up my app to test multi-tenancy by having both localhost and contoso.localhost point to my web app instance.
I set up my hosts file with the corresponding entry:
127.0.0.1 contoso.localhost
However I'm not sure what else I need to do to make this work. Right now I just get a standard IIS8 page when I navigate, even though I haven't done anything in IIS Manager.
I'm trying to avoid having to use IIS locally, as everything is working with IISExpress. Is there any easy way to achieve this?
You need to set your /etc/hosts or C:\Windows\system32\drivers\etc\hosts (as administrator) to reflect the "subdomain". So add 127.0. 0.1 dev. localhost to either file (depending on your platform).
This file is located in the %userprofile%\Documents\IISExpress\config folder or %userprofile%\My Documents\IISExpress\config folder, depending on your OS. When you run a site from a configuration file, you can specify which site to run.
This can be accomplished by editing the applicationHost.config file
C:\Users\yourProfile\Documents\IISExpress\config\applicationHost.config
Visual Studio usually handles editing this file for you when you make configuration changes, but you can manually edit. Find the particular site you are working with and the following bindings should work:
<bindings> <binding protocol="http" bindingInformation="*:5252:localhost" /> <binding protocol="http" bindingInformation="*:5252:contoso.localhost" /> </bindings>
You can really change the port to anything you want so you could use 80 to save yourself some typing. Continue adding bindings to fill out your multi-tenancy as needed.
If you are looking for more information, I would recommend checking out Scott Hanselman's blog post on IIS Express & SSL.
With VS 2015 & .NET core, the applicationHost.config has moved to a directory based system of storing the configuration instead of a global configuration file. The new location is relative to your project:
.vs\config\applicationHost.config
The same editing principals apply to this file, but when using TFS source control VS does not edit the file when changing between branches as it did with the global file.
Regarding the wildcard comment for domains, wildcarding hostname isn't supported until IIS 10. Therefore, it may be supported in IIS Express 10, but probably not before.
The breakdown of the
bindingInformation
is:
bindingInformation="<IPAddress>:<Port>:<Hostname>"
Try checking your project settings for the Project URL.
Right click on your project in the Solution Explorer -> Properties -> Web
Look for Project Url under Servers. Update this value to mirror your subdomain url and you should be good to go.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With