Over the last days, I’ve been working on implementing multiple subdomains with authentication in asp.net for the webapp I’m currently working on.

There are a few steps needed in order to configure IIS, DNS and authentication.

  1. Select the website you’re working on, in the IIS Manager screen, in the left side tree. Then, click the “Bindings” option in the right pane

  1. In the Site Bindings window, add each subdomain that you want to map to your site. Unfortunately, wildcard mapping is not supported, so you’ll have to manually type all the subdomains before using it.

  2. In the windows hosts file (C:\Windows\system32\drivers\etc\hosts), add up each subdomain again, pointing to 127.0.0.1 (see below):

  1. Lastly, you’ll need to update your web.config cookies configuration, so that it is set to work with any subdomain. By default, your login cookies will only be valid for the default subdomain (example.com and www.example.com)
<forms loginUrl="~/Account/Login" timeout="500000" **domain=".example.com"** />

Pay attention for the starting dot in the domain attribute. It is needed in order to work with any subdomain ;)