IIS Express + VS 2015中的通配符主机名 [英] Wildcard hostname in IIS Express + VS 2015
问题描述
我有一个多租户应用程序,在生产中可以作为customer.ourdomain.com
访问.对于使用IIS进行本地开发,我们使用自定义通配符域company-localdev.com
.
I have a multi-tenant application that is accessed in production as customer.ourdomain.com
. For local development with IIS, we use a custom wildcard domain, company-localdev.com
.
使用IIS,无需任何特殊配置即可工作.另一方面,IIS Express仅绑定到localhost
.
With IIS, this works without any particular configuration. IIS Express, on the other hand, only binds to localhost
.
我们正在进行一个向ASP.NET 5的迁移项目,我们希望使用IIS Express来获得更轻松的开发人员体验.
We have an ongoing migration project to ASP.NET 5, and we'd like to use IIS Express for an easier developer experience.
是否可以让IIS Express收听*.company-localdev.com:1234
?奖励点在于,如果这可以自动化,那么开发人员只需在IIS中打开解决方案就可以使其正常工作.
Is it possible to have IIS Express listen to *.company-localdev.com:1234
? Bonus points if this can be automated so a developer can have it working just by opening the solution in IIS.
推荐答案
好,我可以在本地计算机上运行它,这是我必须执行的所有步骤:
Ok I got it working on my local machine, here are all the steps I had to take:
-
转到
{YourProjectFolder}\.vs\config
并编辑 applicationhost.config文件:
Go to
{YourProjectFolder}\.vs\config
and edit the applicationhost.config file:
<site name="MySite" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="{MyProjectFolderPath}" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:49861:localhost" />
<binding protocol="http" bindingInformation="*:80:example.com" />
<!-- for subdomain testing only -->
<binding protocol="http" bindingInformation="*:80:sub1.example.com" />
<binding protocol="http" bindingInformation="*:80:sub2.example.com" />
</bindings>
</site>
以管理员身份运行记事本,然后转到C:\Windows\System32\drivers\etc
以打开主机文件并按如下所示对其进行修改
Run Notepad as Administrator and go to C:\Windows\System32\drivers\etc
to open the hosts file and amend it like so
127.0.0.1 example.com
127.0.0.1 sub1.example.com
127.0.0.1 sub2.example.com
127.0.0.1 example.com
127.0.0.1 sub1.example.com
127.0.0.1 sub2.example.com
通过以管理员身份运行cmd.exe并键入netsh http提示符来添加URL保留(要获得netsh http>
提示符,必须键入netsh
,然后按Enter,然后依次输入http
和Enter
):
Add the url reservation by running cmd.exe as Administrator and typing in the netsh http prompt (to get the netsh http>
prompt, you must type netsh
followed by Enter, then http
followed by Enter
):
add urlacl url=http://example.com:80/ user=everyone
add urlacl url=http://sub1.example.com:80/ user=everyone
add urlacl url=http://sub2.example.com:80/ user=everyone
请记住,关键字everyone
取决于Windows操作系统的语言.在法语操作系统上,user=everyone
应该替换为user="Tout le monde"
,在德语操作系统上,应该替换为user=jeder
,西班牙语是user=todos
等等,这样就可以了.
Bear in mind that the keyword everyone
depends on the language of your Windows OS. On a French OS, user=everyone
shall be replaced by user="Tout le monde"
, on a German OS it should be user=jeder
, in Spanish user=todos
etc... you get the idea.
- 然后,您应该能够开始调试并导航到已设置的域以查看您的网站.
希望这会有所帮助.
这篇关于IIS Express + VS 2015中的通配符主机名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!