Iis – How to run multiple MVC apps within a subdomain on IIS7

asp.net-mvcbindingsiisweb-hosting

Hello and thanks for looking.

Background

I am currently wrapping up a development contract and the client would like for me to push a build of the application to their IIS 7-based server in which they would like to run multiple MVC apps.

One of the issues I have off of the bat is that this server is already a subdomain on their larger network. So, if I enter SERVERNAME in my browser, it automatically directs to SERVERNAME.COMPANYNAME.COM.

Now, this is just fine if I place my application in the default website/root. In this scenario, clicking a link that requests admin.html directs to `SERVERNAME.COMPANYNAME.COM/admin.html' as usual.

BUT they want me to place the app in a subdomain on this server so that they can also run other apps on the same server. So I assume that I need MYAPP.SERVERNAME.COMPANYNAME.COM but I have no idea how to do that.

Complicating matters is that my app and the future ones they wish to install are all MVC based which intercepts and re-writes URLs. I assume that this takes care of itself if I can just successfully get my app into a subdomain to begin with.

What I have tried

  • Creating a new site on the server in it's own app pool
  • Setting the binding for that site to MYAPP.SERVERNAME.COMPANYNAME.COM
  • Setting the binding for that site to MYAPP
  • Setting the binding for that site to MYAPP.SERVERNAME
  • Setting the binding for that site to MYAPP.SERVERNAME.COM
  • Setting the binding for that site to MYAPP.COMPANYNAME.COM

Nothing is working. Am I missing something simple here?

Thanks,

Matt

Best Answer

First thing is are you testing these bindings from the local server? If so, two issues:

  1. For testing purposes you need to be putting your myapp alias in the local hosts file (C:\Windows\System32\Drivers\etc\hosts).
  2. You need to disable loopback protection, which will prevent you from accessing services on a server from itself if you are using a DNS alias. I've got a description of this issue here (it often trips up SharePoint admins). The quick solution (although it disables a minor security feature of Windows) is to run this from a PowerShell (run as administrator) prompt: New-ItemProperty HKLM:\System\CurrentControlSet\Control\Lsa -Name "DisableLoopbackCheck" -value "1" -PropertyType dword -Force and reboot.

After that, I would say overall that this isn't related to MVC as much as it is DNS. You can make as many Web Sites in IIS as you want (MVC or other) and make up any DNS names you want as long as you TELL the network DNS servers about the name to IP matches so people can find them.

Sounds like you're used to just putting a site on a server and then using http://servername from other computers on the network. What I always prefer to do is NEVER use the hostname for web apps. I would create a "DNS Alias" in whatever DNS solution the network admin uses (likely Windows DNS Server) to point "appname" to be an alias of "servername". Then in the Web Site binding I put in the host header I want. The advantage here is twofold, I can put more then one web app on a server, and I can then move that web app elsewhere without telling users (just change DNS Alias pointer).

So in your case I recommend http://myapp (assuming it's for internal-only) and in their DNS Zone for companyname.com they just add a DNS Alias (CNAME record) for myapp to point to servername.

If you think it will be accessible from firewall via Internet, then you'll want to use the FQDN like http://myapp.companyname.com. Same steps for DNS apply, you just need to also put it in Internet DNS as well.

I would NOT do sub-domains of the web server name, because that just makes all apps on it tied to that web server (you can't move them without pain for each user in changing their links and habits). There's no less/more work to myapp.companyname.com or myapp.servername.companyname.com so why not make it easier for everyone with myapp.companyname.com. If they tell you it's for identifying the location easier, that's what the DNS Alias is for... just ping myapp.companyname.com and the DNS Alias will cause ping to tell you the REAL server DNS name.