在 IIS Express 中使用自定义域 [英] Using Custom Domains With IIS Express

查看:21
本文介绍了在 IIS Express 中使用自定义域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

传统上,我在我的本地主机开发服务器上使用自定义域.类似的东西:

Traditionally I use custom domains with my localhost development server. Something along the lines of:

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

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

This has provided me a ton of flexibility when working with external API's such as Facebook. This has worked great in the past with the built in Visual Studio Development Server, because all I needed to do was add a CNAME to those DNS records pointing to 127.0.0.1.

但是,我无法让它与 IIS Express 一起使用.我尝试过的一切似乎都失败了.我什至在 IIS Express 的 applicationHost.config 文件中添加了正确的 XML 配置,但它似乎无法将这些条目识别为 IIS 的真实安装那样有效.

However I have not been able to get this to work with IIS Express. Everything I have tried seems to have failed. I have even added the correct XML config to the applicationHost.config file for IIS Express, but it doesn't seem to recognize the entries as valid as a true install of IIS would.

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

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

Whenever I enter this line and try to request http://dev.example.com:1288 I get the following message:

错误请求 - 无效主机名

Bad Request - Invalid Hostname

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

Does anybody know if I am missing something obvious? Or did the IIS Express team really lack the foresight to see this type of use?

推荐答案

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

This is what worked for me (Updated for VS 2013, see revision history for 2010, for VS 2015 see this: https://stackoverflow.com/a/32744234/218971):

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

  1. Right-click your Web Application Project ▶ PropertiesWeb, then configure the Servers section as follows:

  • 从下拉菜单中选择 IIS Express ▼
  • 项目网址:http://localhost
  • 覆盖应用程序根 URL:http://dev.example.com
  • 单击创建虚拟目录(如果您在此处遇到错误,您可能需要禁用 IIS 5/6/7/8,将 IIS 的 Default Site 更改为除端口之外的任何内容:80,请确保 Skype 未使用端口 80 等)
  • Select IIS Express ▼ from the drop down
  • Project Url: http://localhost
  • Override application root URL: http://dev.example.com
  • Click Create Virtual Directory (if you get an error here you may need to disable IIS 5/6/7/8, change IIS's Default Site to anything but port :80, make sure Skype isn't using port 80, etc.)

可选:将 Start URL 设置为 http://dev.example.com

打开 %USERPROFILE%My DocumentsIISExpressconfigapplicationhost.config(Windows XP、Vista 和 7)并在 中编辑站点定义; 配置块遵循以下几行:

Open %USERPROFILE%My DocumentsIISExpressconfigapplicationhost.config (Windows XP, Vista, and 7) and edit the site definition in the <sites> config block to be along the lines of the following:

<site name="DevExample" id="997005936">
    <application path="/" applicationPool="Clr2IntegratedAppPool">
        <virtualDirectory
            path="/"
            physicalPath="C:path	oapplication
oot" />
    </application>
    <bindings>
        <binding
            protocol="http"
            bindingInformation=":80:dev.example.com" />
    </bindings>
    <applicationDefaults applicationPool="Clr2IntegratedAppPool" />
</site>

  • 如果运行 MVC:确保 applicationPool 设置为集成"之一选项(如Clr2IntegratedAppPool").

  • If running MVC: make sure the applicationPool is set to one of the "Integrated" options (like "Clr2IntegratedAppPool").

    打开您的hosts 文件并添加行 127.0.0.1 dev.example.com.

    ► 启动您的应用程序!

    来自评论的一些很好的建议:

    Some great advice from the comments:

    • 您可能需要以管理员身份运行 Visual Studio.
    • 如果你想让其他开发者看到你的 IIS 运行 netsh http add urlacl url=http://dev.example.com:80/user=everyone
    • 如果您希望站点为所有主机解析,请设置 bindingInformation="*:80:".使用任何你想要的端口,80只是方便.要解析所有主机,您需要以管理员身份运行 Visual Studio
    • 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 Express 中使用自定义域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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