I have a set up an ASP.net MVC application in my IIS at port 80. The website resolves for any subdomain. Like dev.localhost,test.localhost etc. No I have not set up any of these sub domain on my machine. I have no host file entries except the default, and no host header. From everything I have read online, it looks like to configure a subdomain you need do a host file entry and add host header. How is this working without me doing anything? Have I set up my site incorrectly?
3 Answers
My intuition (though I haven't verified this for ASP.Net MVC) is that it has 'reserved' the url http://+:80/ for your application - this means that any domain name on port 80 that resolves to localhost (*.localhost, 127.0.0.1, hosts file entires etc.) will be routed (by the OS and IIS) to your ASP.Net process for it to handle.
There are a couple of ways to verify this:
- You can check in the IIS administrator panel (if you're not using IISExpress) what URLs it has nabbed (under 'Site bindings' for the app). 'All unassigned' will (I think) route all requests to that port - no matter the host/subdomain - to your site;
- or you can use netsh to find out what URLs are reserved:
Example netsh command:
$ netsh http show urlacl

- 9,898
- 7
- 40
- 59
-
Thank you for all the answers. All of you are correct. – InsaneKarma Jun 08 '15 at 14:21
I would guess you have a single website with no hostname for the http binding so all requests are going to it. If you fill in "localhost" in the hostname it should no longer work for the subdomains unless you add entries in the hosts.

- 1,690
- 12
- 14
-
But the system would still have to resolve whatever.localhost and it should not do that unless you configure something, right? Configuring a website in IIS with no hostname/binding is not enough on it's own. – HaukurHaf Jun 05 '15 at 20:09
-
Localhost is known whether you have an entry or not. It is still resolved to your local address. Do a "nslookup localhost" and it points to 127.0.0.1. – Alioza Jun 05 '15 at 20:13
-
I know that, but the OP states that dev.localhost, test.localhost etc. work without him doing anything ("I have no host file entries except the default"), which makes no sense to me. – HaukurHaf Jun 05 '15 at 20:17
-
I guess that the OP is just mixing terms, confusing host file entries with host header entries. For dev.localhost etc. to work, a host file entry (or a DNS record) is definitely needed. – HaukurHaf Jun 05 '15 at 20:28
Subdomains will just route to port 80 like the primary domain based on DNS resolution. If you don't have multiple bindings in IIS then the primary binding will serve all requests.

- 31
- 3