Iis – Wildcard subdomains on localhost using IIS7

iissubdomainwildcard

I'm running IIS 7 on Windows 7 and would like to setup wildcard subdomains to test out an ASP.NET multi-tenant application that uses the subdomain to identify the user. How can I achieve this?

Best Answer

Update 2016

IIS 10 in Windows 2016 supports wildcard host headers.

Origin answer

Unfortunately IIS 7 still doesn't support wildcard mappings for subdomains (or any part of the domain binding).

You have a few options:

  • If you can ensure the site only receives traffic on one IP and you own/have dedicated access to the server, you can use DNS to "fake" out the behavior with a wildcard mapping and no host. There is a great post on this at http://dirk.net/2008/05/28/wildcard-host-header-binding-and-subdomains-with-iis7

  • Simply let the site respond to all traffic, or all traffic using a supported binding, and let ASP.NET handle the subdomain processing. Basically everything hits IIS and ASP.NET, and then you use code for the sub-domain control. Your APP is at the root, and the subdomains and simply used by the app to obtain the user info.

  • Use some sort of traffic control/url-rewrite module to rewrite requests to user or user2.domain.com to just app.domain.com (or whatever) with some additional header (i.e. 'X-UserInfo') that contains the username, and your app handles the username that way

Related Topic