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

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

问题描述

传统上我将自定义域用于我的localhost开发服务器。类似的东西:

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

在使用外部API(如Facebook)时,这为我提供了很大的灵活性。这在过去使用内置的Visual Studio开发服务器时效果很好,因为我需要做的就是为那些指向 127.0.0.1 的DNS记录添加一个CNAME。 / p>

但是我无法使用IIS Express。我尝试的一切似乎都失败了。我甚至已经为IIS Express的 applicationHost.config 文件添加了正确的XML配置,但它似乎没有认识到这些条目与真正安装的IIS一样有效。

 < binding protocol =httpbindingInformation =*:1288:dev.example.com/> 

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


错误请求 - 无效主机名


有人知道我是否遗漏了一些明显的东西吗?或者IIS Express团队是否真的缺乏远见才能看到这种类型的使用?

解决方案

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


  1. 右键单击您的Web应用程序项目▶属性 Web ,然后配置服务器部分,如下所示:


    • 从下拉列表中选择 IIS Express▼

    • 项目网址: http:// localhost

    • 覆盖应用程序根URL: http://dev.example.com

    • 单击创建虚拟目录(如果您在此处收到错误,则可能需要禁用IIS 5/6/7/8,更改IIS的默认站点除了端口:80 以外的所有内容,请确保 Skype不使用端口80 等。)


  2. 可选:将起始网址设置为 http://dev.example.com

  3. 打开%USERPROFILE%\ My文件\ IISExpress\config\applicationhost.config (Windows XP,Vista和7)并在< sites> 配置块中编辑网站定义,使其符合以下内容:

     < site name =DevExampleid =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 设置为Integrated选项之一(如Clr2IntegratedAppPool)。


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

  6. ►开始您的申请!

评论提供了一些很好的建议:



  • 您可能需要运行Visual Studio管理员。

  • 如果你想让其他开发者看到你的IIS运行 netsh http add urlacl url = http://dev.example.com:80 / user =每个人

  • 如果您希望网站解析所有主机设置 bindingInformation =*:80:
    使用你想要的任何端口,80只是方便。



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

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

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.

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" />

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

Bad Request - Invalid Hostname

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?

解决方案

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. Right-click your Web Application Project ▶ PropertiesWeb, then configure the Servers section as follows:
    • 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.)
  2. Optionally: Set the Start URL to http://dev.example.com
  3. Open %USERPROFILE%\My Documents\IISExpress\config\applicationhost.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\to\application\root" />
        </application>
        <bindings>
            <binding
                protocol="http"
                bindingInformation=":80:dev.example.com" />
        </bindings>
        <applicationDefaults applicationPool="Clr2IntegratedAppPool" />
    </site>
    

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

  5. Open your hosts file and add the line 127.0.0.1 dev.example.com.
  6. ► Start your application!

Some great advice from the comments:

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

这篇关于使用IIS Express自定义域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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