Configure DNS Aliases in IISExpress for localhost

A direction we are taking Process PA is white labelling for our partners. To do this we are still hosting on the same scalable platform on Microsoft Azure and essentially adding another level of multi-tenanting in our codebase. When a user navigates to https://app.processpa.com/ they will get our first party branded experience. However, when a user navigates to something like https://partner1.processpa.com, they will get a tailored experience complete with branding, different resources, templates and features specific for those customers supported by our partners.

Building out the experience using Dependency Injection with Branch By Abstraction based on the host is reasonably straight forward. I however wanted the local development environment to be run in the same way, rather than switching in code for whatever partner experience was being built out at the time. To do this I need to be able to configure local DNS records for localhost and IISExpress. The answer I found on StackOverflow but below are the simplest steps that worked for me.

  1. Open Notepad as an Administrator
  2. Open in Notepad C:\Windows\System32\drivers\etc\hosts
  3. Copy the comment lines for localhost host and add as your DNS records
    127.0.0.1    partner1.localhost
    ::1          partner1.localhost
  4. For Visual Studio 2015, open <Solution folder>\.vs\config\applicationhost.config
  5. Find the site and add the bindings you need, making sure to change the ports.
    <bindings>
    <binding protocol="http" bindingInformation="*:1704:localhost" />
    <binding protocol="https" bindingInformation="*:44300:localhost" />
    <binding protocol="http" bindingInformation="*:1705:partner1.localhost" />
    <binding protocol="https" bindingInformation="*:44308:partner1.localhost" />
    </bindings>
  6. To prevent the need to run Visual Studio as admin to start IISExpress on those ports, open an Administrator command prompt and run:
    netsh http add urlacl url=http://partner1.localhost:1705/ user=machine\username
    netsh http add urlacl url=https://partner1.localhost:44308/ user=machine\username

If you have certificate trust issues check out: https://blogs.msdn.microsoft.com/robert_mcmurray/2013/11/15/how-to-trust-the-iis-express-self-signed-certificate/.

And that’s it! When you go to https://localhost:44300 or https://partner1.localhost:44308 you get the same application with a different experience.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s