0

I'm building a MVC web application that should respond to domains like a.sub.example.com, b.sub.example.com, c.sub.example.com etc. I'm ok figuring out how to get out the a,b,c etc prefix and create a proper route accordingly, but I'm struggling to get the IIS webserver to actually forward the requests to the same webapplication.

I followed this guide to make IIS express listen to another address, in this case sub.example.com, which works fine. However, I cannot figure out how to get it to listen to all subdomains of that one. When I direct my browser to a.sub.example.com, I get an error:

HTTP Error 400. The request hostname is invalid.

I added both sub.example.com and a.sub.example.com as aliases for 127.0.0.1 in my hosts file.

My applicationhost.config file's 'site' entry looks like this:

<site name="MyProject.Web" id="7">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="..." />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:8888:sub.example.com" />
    </bindings>
    <applicationDefaults applicationPool="Clr2IntegratedAppPool" />
</site>

When I replace the 'bindingInformation attribute with

"*:8888:*.sub.example.com" 

as the previously mentioned guide suggests I should do when I want IIS express to listen to multiple domains, IIS Express fails to start at all.

Am I missing something obvious here?

Community
  • 1
  • 1
jkokorian
  • 2,905
  • 7
  • 32
  • 47
  • Check this link for information regarding sub domains with MVC. http://csharptechies.blogspot.com/2013/11/subdomain-with-aspnet-mvc-using.html – pool pro Jul 24 '15 at 20:20
  • The blogpost you suggest is mainly about how to properly setup an mvc route to make the subdomain link to an area. As far as I could see there is nothing in it about how to get IIS express to support subdomains. – jkokorian Jul 27 '15 at 21:47

1 Answers1

0

The way i know of is to set the IIS applicationhost.config (Full path: %UserProfile%\Documents\IISExpress\config\applicationhost.config) and find the referance to the port number.

<site name="WebSite1" id="1">
      <application path="/">
            <virtualDirectory path="/" physicalPath="%IIS_SITES_HOME%WebSite1" />
      </application>
      <bindings>
            <binding protocol="http" bindingInformation=":49483:localhost" />
      </bindings>
</site>

i normaly add <binding protocol="http" bindingInformation=":49483:" /> to accept all hosts on that port (note empty string, not wildcard *).

You will have to have set up this host to point to 127.0.0.1 in your hosts file. Or, use a domain you own and point .sub.mydomain to 127.0.0.1. Hosts file doesn’t support wildcards () but DNS does! This means I can easily set up myproject.sub.mydomain and myproject.sub.mydomain without having to add new lines to my hosts file (so long as I have an internet connection)!

Hope this helps

pool pro
  • 2,084
  • 12
  • 21
  • Changing the bindingInformation to just ":8888:" did the trick, but I still need to put every subdomain in my hosts file separately. When I put 127.0.0.1 .sub.example.com in my hosts file, I get an "ERR_NAME_NOT_RESOLVED" error in my browser. – jkokorian Aug 02 '15 at 11:31
  • try not to use the domain name in your host file. just the sub-name, if you want test.localhost just use test without the domain, – pool pro Aug 02 '15 at 18:14