32

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?

1

2 Answers 2

47

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.

Update

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>"

Sign up to request clarification or add additional context in comments.

8 Comments

My path was actually C:\Users\myaccount\Documents\IISExpress
@beavel I tried this but I am still getting 400 bad request ..any thought?
is it possible to bind *.localhost?
consider you have to run visual studio as administrator and the config file address changed to '\your-Project-root\.vs\config\applicationhost.config' in .NET Core project.
Didn't work initially. Adding 127.0.0.1 mysub.localhost to C:\Windows\System32\drivers\etc\hosts file seemed to help.
|
1

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.

1 Comment

I need to be able to use localhost and contoso.localhost at the same time - I don't see a way to configure multiple URLs with this approach. thoughts?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.