6

I have a multi-tenant website that has to take care of any incoming request and determine the appropriate routing by the URL subdomain.

I set up the subdomain routing using this or a similar solution.

However I'm trying to access my website on my local machine using subdomains an alias website. I'm unable to get my local IIS to port to my website with the subdomain I've specified.
I want to dedicate a virtual domain name in my local machine that will port to the website I'm debugging on VS (localhost:23456).

I've read some answers of identical questions (like this or this one), but it looks like the system has changed with the new IIS and Visual Studio 2015 and ASP.NET 5 MVC 6 (vNext) project configuration.

Here's what I've tried according to the answers linked above:

  • I tried setting the hosts file porting www.myexample.com to 127.0.0.1 but I get a "Bad request" error when navigating to www.myexample.com:23456 in my browser, and anyway the debugger doesn't report a request.
  • I tried setting <binding protocol="http" bindingInformation=":23456:www.myexample.com" /> in the applicationhost.config file, gets IIS to raise an error saying "Replace hostname with localhost. Any other bindingInformation not specificying localhost as the website raises that IIS error.

Update

After opiants answer

I knew about the .vs folder and that's were I was configuring the bindings indeed.
However, looks like it was the permission that caused IIS to throw errors. Running that netsh command solved the issue. And BTW, since I'm only running it my own machine, I'm not gonna need to open the firewall.

Anyway my question is if there is a way to add a wildcard instead of each subdomain separately? Since each tenant gets a unique subdomain, the whole process of adding subdomains is going to be dynamic by nature. I need to allow an asterisk in all the 3 places:

  • hosts file
  • applicationhost.config file
  • netsh command

It looks like I can add the asterisk in those places but it doesn't actually work.

Community
  • 1
  • 1
Shimmy Weitzhandler
  • 101,809
  • 122
  • 424
  • 632

1 Answers1

6

I'm guessing you're using IIS express locally?

If so, in your solution directory, there is a .vs folder. You need to add the binding in the \config\applicationhost.config file inside that folder. Then make sure that you've allowed IIS express to listen to that subdomain.

You can refer to Scott's article on how to configure IIS Express. Specifically look for this paragraph "1. GETTING IIS EXPRESS TO SERVE EXTERNALLY OVER PORT 80"

To be more specific, you need to run these commands:

netsh http add urlacl url=http://{your-domain}:{custom-port}/ user=everyone

netsh firewall add portopening TCP {custom-port} IISExpressWeb enable ALL

Dealdiane
  • 3,984
  • 1
  • 24
  • 35
  • Thanks. It's working now. Looks like it's the `netsh` command I had to run. But I want to use an asterisk instead of manually adding all subdomains in all places. Please see the update on my question. – Shimmy Weitzhandler Aug 18 '15 at 00:40
  • You can add a wildcard mapping. `` `netsh http add urlacl url=http://*:23456/ user=everyone` As you might've already guessed, this will match _every_ domain name and without registering the domain to a dns server, you'll have to create a mapping in the hosts file for each subdomain. – Dealdiane Aug 18 '15 at 01:46
  • I tried adding a wildcard for the subdomain only and I couldn't get it to work. Have I missed something? – Shimmy Weitzhandler Aug 18 '15 at 01:54
  • 1
    Do you mean like `*.something.com`? I'm afraid IIS Express does not support that. – Dealdiane Aug 18 '15 at 01:57
  • I guess I'll have to make an external process that sets up the three stages manually upon each addition/removal of a tenant. Do you think about a better option? Is this even possible in .NET Core / DNX? – Shimmy Weitzhandler Aug 18 '15 at 02:16
  • Not exactly sure what you're trying to accomplish there but I suppose you can make it dynamic by creating a handler that will match the subdomain against a tenant? – Dealdiane Aug 18 '15 at 02:42
  • Yeah, but I need my computer to navigate `*.myexample.com` to my debugger... I think the `netsh` command treats `*` separately as if it would have been a subdomain, meaning it's not treated as an asterisk. – Shimmy Weitzhandler Aug 20 '15 at 00:53
  • Thank you very much. You solved my problem with subdomain. I can confirm for asp.net 5 (vNext) - IIS Express following: 1. Edit hosts file, 2. edit \config\applicationhost.config and 3. netsh http add urlacl url=http://{your-domain}:{custom-port}/ user=everyone netsh firewall add portopening TCP {custom-port} IISExpressWeb enable ALL – Miroslav Siska Oct 27 '15 at 21:57
  • @Miroslav Thanks, Point 1: Edit Hosts file is required, should possibly be re-iterated in the answer... – Mark Redman Feb 07 '16 at 07:56