ASP.NET Core在IIS Express中的虚拟目录

10

我在使用VS2015创建的一个解决方案中,创建了两个ASP.NET Core Web和API项目。

src
|
|-app.web
|  |-localhost:29999/
|  |-startup.cs 
|  
|-app.api
   |-localhost:29999/api/
   |-startup.cs (app.Map("/api", api => { /*configs and route*/ });)

并且修改 .vs\config\applicationhost.config 文件如下以使用虚拟目录

<site name="ThreeCON.Web" id="2">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
      <virtualDirectory path="/" physicalPath="C:\proj\src\app.web\wwwroot" />
      <virtualDirectory path="/api" physicalPath="C:\proj\src\app.api\wwwroot" />
    </application>
    <bindings>
      <binding protocol="http" bindingInformation="*:29999:localhost" />
    </bindings>
</site>

当我在调试时尝试访问URL localhost:29999/api 时,我遇到了404未找到的错误(其中localhost:29999/可以正常工作)。

但是,当我通过在IIS中创建虚拟目录将其部署到开发服务器时,它可以正常工作。那么我该如何修复这个问题以使其与IIS Express一起正常工作?

1个回答

5
问题在于虚拟目录未被识别,因为这是由Kestrel处理而不是IIS Express。基本上,Kestrel不知道虚拟目录的存在,因此无法像这样提供它。 答案,以及答案中提供的博客文章链接,让我得出了这个结论并解决了我也遇到的这个问题。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接