使用 VS 2015 对子域进行本地调试 [英] Local debugging of subdomains with VS 2015

查看:23
本文介绍了使用 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.

我使用 this 或类似解决方案设置子域路由.

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).

我已经阅读了一些相同问题的答案(例如 thisthis one),但看起来系统随着新的 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:

  • 我尝试将 hosts 文件移植 www.myexample.com 设置为 127.0.0.1 但我收到错误请求"在我的浏览器中导航到 www.myexample.com:23456 时出错,并且无论如何调试器都不会报告请求.
  • 我尝试设置 applicationhost.config 文件中,让 IIS 引发错误提示将 hostname 替换为 localhost.任何其他未指定 localhostbindingInformation 网站都会引发该 IIS 错误.
  • 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.

opants 回答后

我知道 .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 文件夹.您需要在该文件夹内的 configapplicationhost.config 文件中添加绑定.然后确保您已允许 IIS express 侦听该子域.

If so, in your solution directory, there is a .vs folder. You need to add the binding in the configapplicationhost.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 添加 urlacl url=http://{your-domain}:{custom-port}/user=everyone

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

这篇关于使用 VS 2015 对子域进行本地调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆