gpt4 book ai didi

iis - 将自定义域与 IIS Express 结合使用

转载 作者:行者123 更新时间:2023-12-03 04:01:11 24 4
gpt4 key购买 nike

传统上,我在本地主机开发服务器中使用自定义域。大致如下:

dev.example.com
dev.api.example.com

这为我在使用 Facebook 等外部 API 时提供了极大的灵 active 。这在过去与内置的 Visual Studio 开发服务器配合使用非常有效,因为我所需要做的就是向那些指向 127.0.0.1 的 DNS 记录添加 CNAME。

但是,我无法让它与 IIS Express 一起工作。我所尝试的一切似乎都失败了。我什至已将正确的 XML 配置添加到 IIS Express 的 applicationHost.config 文件中,但它似乎无法像真正安装 IIS 那样识别这些条目。

<binding protocol="http" bindingInformation="*:1288:dev.example.com" />

每当我输入此行并尝试请求 http://dev.example.com:1288 时,我都会收到以下消息:

Bad Request - Invalid Hostname

有人知道我是否遗漏了一些明显的东西吗?或者 IIS Express 团队真的缺乏预见这种用途的远见吗?

最佳答案

这对我有用(针对 VS 2013 进行了更新,请参阅 2010 年的修订历史记录,对于 VS 2015 请参阅: https://stackoverflow.com/a/32744234/218971 ):

  1. 右键单击您的 Web 应用程序项目 ▶ PropertiesWeb ,然后配置Servers部分如下:

    • 从下拉菜单中选择IIS Express ▼
    • 项目网址:http://localhost
    • 覆盖应用程序根 URL:http://dev.example.com
    • 点击创建虚拟目录(如果此处出现错误,您可能需要禁用 IIS 5/6/7/8,将 IIS 的 Default Site 更改为端口 :80 以外的任何端口,确保Skype isn't using port 80等)
  2. 可选:设置 Start URLhttp://dev.example.com

  3. 打开%USERPROFILE%\My Documents\IISExpress\config\applicationhost.config (Windows XP、Vista 和 7)并编辑 <sites> 中的站点定义配置 block 应遵循以下内容:

    <site name="DevExample" id="997005936">
    <application path="/" applicationPool="Clr2IntegratedAppPool">
    <virtualDirectory
    path="/"
    physicalPath="C:\path\to\application\root" />
    </application>
    <bindings>
    <binding
    protocol="http"
    bindingInformation=":80:dev.example.com" />
    </bindings>
    <applicationDefaults applicationPool="Clr2IntegratedAppPool" />
    </site>
  4. 如果运行 MVC:请确保 applicationPool设置为“集成”选项之一(如“Clr2IntegratedAppPool”)。

  5. 打开您的 hosts file并添加行 127.0.0.1 dev.example.com .

  6. ► 开始您的应用程序!

评论中的一些很好的建议:

  • You may need to run Visual Studio as Administrator.
  • If you want to make other devs see your IIS run netsh http add urlacl url=http://dev.example.com:80/ user=everyone
  • If you want the site to resolve for all hosts set bindingInformation="*:80:".Use any port you want, 80 is just convenient. To resolve all hosts you'll need to run Visual Studio as an administrator

关于iis - 将自定义域与 IIS Express 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4709014/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com