使用VS 2015进行子域的本地调试 [英] Local debugging of subdomains with VS 2015
问题描述
我有一个多租户网站,它必须处理所有传入请求并通过URL子域确定适当的路由.
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.
但是,我试图使用子站点(别名网站)访问本地计算机上的网站.我无法使用指定的子域将本地IIS移植到我的网站.
我想在本地计算机上指定一个虚拟域名,该虚拟域名将移植到我正在VS(localhost:23456
)上调试的网站上.
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
).
我已经阅读了一些相同问题的答案(例如 this 或(此一个),但看起来系统已随着新的IIS和Visual Studio 2015和ASP.NET 5 MVC发生了变化6(vNext)项目配置.
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:
- 我尝试将端口
www.myexample.com
的hosts
文件端口设置为127.0.0.1
,但收到错误请求"消息,在我的浏览器中导航到www.myexample.com:23456
时发生错误,并且调试器始终不报告请求. - 我尝试在 applicationhost.config 文件中设置
<binding protocol="http" bindingInformation=":23456:www.myexample.com" />
,使IIS出现错误,提示用 localhost 替换 hostname .其他未指定localhost
的bindingInformation
,因为该网站引发IIS错误.
- I tried setting the
hosts
file portingwww.myexample.com
to127.0.0.1
but I get a "Bad request" error when navigating towww.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 otherbindingInformation
not specificyinglocalhost
as the website raises that IIS error.
我知道 .vs 文件夹,那是我确实在配置绑定的原因.
但是,似乎是导致IIS引发错误的权限.
运行该netsh
命令解决了该问题.顺便说一句,由于我只在自己的机器上运行它,所以我不需要打开防火墙.
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.
无论如何,我的问题是是否有办法添加通配符而不是分别添加每个子域?由于每个租户都有一个唯一的子域,因此添加子域的整个过程本质上将是动态的.我需要在所有3个地方都加一个星号:
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:
- 主机文件
- applicationhost.config文件
- netsh命令
看起来我可以在这些位置添加星号,但实际上不起作用.
It looks like I can add the asterisk in those places but it doesn't actually work.
推荐答案
我猜您在本地使用IIS Express?
I'm guessing you're using IIS express locally?
如果是,则在解决方案目录中,有一个.vs
文件夹.您需要在该文件夹内的\config\applicationhost.config
文件中添加绑定.然后确保您已允许IIS Express侦听该子域.
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.
您可以参考Scott的有关如何配置IIS Express的文章.专门查看该段落" 1.使IIS EXPRESS在端口80上提供外部服务"
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
这篇关于使用VS 2015进行子域的本地调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!