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

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

这为我在使用外部api(如Facebook)时提供了很大的灵活性。这在过去与内置的Visual Studio Development Server一起工作得很好,因为我所需要做的只是向指向127.0.0.1的DNS记录添加一个CNAME。

但是,我还不能让它与IIS Express一起工作。我所做的一切努力似乎都失败了。我甚至向applicationHost添加了正确的XML配置。IIS Express的配置文件,但它似乎不能像真正安装IIS那样识别有效的条目。

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

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

错误请求-无效的主机名

有人知道我是否遗漏了什么明显的东西吗?或者IIS Express团队真的缺乏预见到这种类型的使用?


当前回答

在我的WebMatrix IIS Express安装中,从“*:80:localhost”更改为“*:80:custom”。hostname“没有工作(“坏的主机名”,即使有适当的etc\hosts映射),但“*:80:”工作-并且没有其他答案所要求的额外步骤。注意,“*:80:*”不会这样做;去掉第二个星号。

其他回答

无效的主机名表明您在IIS Express配置文件中配置的实际站点(很可能)未运行。IIS Express没有IIS那样的流程模型。


要运行站点,需要显式启动(通过从webmatrix打开并访问,或者通过命令行调用iisexpress.exe(从它的安装目录),并使用/site参数。


通常,允许使用完全限定的DNS名称进行本地访问的步骤如下 让我们使用DNS名称dev.example.com的示例

edit %windows%\system32\drivers\etc\hosts file to map dev.example.com to 127.0.0.1 (admin privilege required). If you control DNS server (like in Nick's case) then the DNS entry is sufficient as this step is not needed. If you access internet through proxy, make sure the dev.example.com will not be forwared to proxy (you have to put in on the exception list in your browser (for IE it would be Tools/Internet Options/Connections/Lan Settings, then go to Proxy Server/Advanced and put dev.example.com on the exeption list. Configure IIS Express binding for your site (eg:Site1) to include dev.example.com. Administrative privilege will be needed to use the binding. Alternatively, a one-time URL reservation can be made with http.sys using netsh http add urlacl url=http://dev.example.com:<port>/ user=<user_name> start iisexpress /site:Site1 or open Site1 in WebMatrix

按照Jaro的建议,我可以在Windows XP和IIS Express(通过Web Matrix安装)下进行小的修改,并且不局限于localhost。这只是一个正确设置绑定的问题。

Use WebMatrix to create a new site from folder in your web application root. Close WebMatrix. Open %USERPROFILE%\My Documents\IISExpress\config\applicationhost.config (Windows XP. Vista and 7 paths will be similar) 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>

如果运行MVC,则将applicationPool设置为“Integrated”选项之一。

对于Visual Studio 2015,上述答案中的步骤适用,但应用程序主机。配置文件在一个新的位置。在你的“解决方案”文件夹中,如果你升级了,并且有两个版本的applicationhost,这是令人困惑的。在您的机器上配置。

\.vs\config

在该文件夹中,您将看到您的applicationhost。配置文件

或者,您也可以在解决方案文件夹中搜索.config文件并以这种方式找到它。

我个人使用以下配置:

在我的hosts文件中包含以下内容:

127.0.0.1       jam.net
127.0.0.1       www.jam.net

下面是我的applicationhost。配置文件:

<site name="JBN.Site" id="2">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="C:\Dev\Jam\shoppingcart\src\Web\JBN.Site" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:49707:" />
            <binding protocol="http" bindingInformation="*:49707:localhost" /> 
    </bindings>
</site>

记得以管理员身份运行visual studio 2015实例!如果你不想每次都这样做,我建议:

默认情况下,作为管理员如何运行Visual Studio ?

我在尝试升级到visual studio 2015时遇到了问题,并意识到我的配置都没有被转移。

这是为我工作(更新的VS 2013,见2010年的修订历史,VS 2015见这个:https://stackoverflow.com/a/32744234/218971):

Right-click your Web Application Project ▶ Properties ▶ Web, 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.) Optionally: Set the Start URL to http://dev.example.com 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> If running MVC: make sure the applicationPool is set to one of the "Integrated" options (like "Clr2IntegratedAppPool"). Open your hosts file and add the line 127.0.0.1 dev.example.com. ► Start your application!

评论中有一些很棒的建议:

您可能需要以管理员身份运行Visual Studio。 如果你想让其他开发人员看到你的IIS,运行netsh http add urlacl url=http://dev.example.com:80/ user=everyone 如果您希望站点为所有主机解析,请设置bindingInformation="*:80:"。 使用任何端口,80只是方便。要解析所有主机,您需要以管理员身份运行Visual Studio

在我的WebMatrix IIS Express安装中,从“*:80:localhost”更改为“*:80:custom”。hostname“没有工作(“坏的主机名”,即使有适当的etc\hosts映射),但“*:80:”工作-并且没有其他答案所要求的额外步骤。注意,“*:80:*”不会这样做;去掉第二个星号。