Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Local debugging of subdomains with VS 2015

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.

like image 687
Shimmy Weitzhandler Avatar asked Aug 17 '15 20:08

Shimmy Weitzhandler


1 Answers

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

like image 107
Dealdiane Avatar answered Nov 18 '22 13:11

Dealdiane