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

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团队真的缺乏预见到这种类型的使用?


当前回答

我使用iisexpress-proxy(从npm)来实现这一点。

https://github.com/icflorescu/iisexpress-proxy

其他回答

以防万一有人需要…

我的要求是:

启用SSL 自定义的域 运行在(默认)端口:443

在IISExpress中设置这个URL: http://my.customdomain.com

为了设置这个,我使用了以下设置:

项目网址:http://localhost:57400

起始URL: http://my.customdomain.com

/ .vs / {solution-name} / config / applicationhost。配置设置:

<site ...>
    <application>
        ...
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:57400:" />
        <binding protocol="https" bindingInformation="*:443:my.customdomain.com" />
    </bindings>
</site>

把这个留在这里,以防有人需要…

我需要在IIS Express中为Wordpress Multisite设置自定义域,但在我以管理员身份运行Webmatrix/Visual Studio之前,任何东西都不起作用。然后我就可以将子域绑定到同一个应用程序。

<bindings> 
    <binding protocol="http" bindingInformation="*:12345:localhost" />
    <binding protocol="http" bindingInformation="*:12345:whatever.localhost" />
</bindings>

然后转到http://whatever.localhost:12345/将运行。

对于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时遇到了问题,并意识到我的配置都没有被转移。

按照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”选项之一。

并对该方法进行了测试。NET Core 3.1和Visual Studio 2019。

vs PROJECTNAME \配置\ applicationhost。配置

将“*:44320:localhost”修改为“*:44320:*”。

<bindings>
    <binding protocol="http" bindingInformation="*:5737:localhost" />
    <binding protocol="https" bindingInformation="*:44320:*" />
</bindings>

这两个链接都有效:

https://localhost:44320 https://127.0.0.1:44320

现在,如果你想让应用程序与自定义域一起工作,只需要在主机文件中添加以下一行:

C:\Windows\System32\drivers\etc\hosts

127.0.0.1 customdomain

Now:

https://customdomain:44320

注意:如果你的应用在没有SSL的情况下工作,请更改protocol="http"部分。