ASP.NET 5 将应用程序添加为 IIS 应用程序

ASP.NET 5 add app as IIS application

我正在将一些应用程序从 ASP.NET 5 beta7 迁移到 RC1。使用 HTTPPlatformHandler 我能够 运行 这些 ASP.NET 5 RC1 应用程序中的任何一个作为 IIS 站点的根。但它们不会 运行 作为站点的子目录(右键单击 'add application')。完整回复显示:

HTTP/1.1 404 Not Found
Content-Length: 0
Server: Kestrel
X-Powered-By: ASP.NET
Date: Tue, 24 Nov 2015 14:59:04 GMT

这不是权限问题,因为当应用程序是站点的根目录并使用相同的应用程序池时,路由已成功提供。

应用程序池配置为 'no managed code' 和集成管道。

根应用程序的 web.config 如下所示:

<configuration>
  <system.webServer>
    <handlers>
      <add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
    </handlers>
    <httpPlatform processPath="..\approot\web.cmd" arguments="" stdoutLogEnabled="false" stdoutLogFile="..\logs\stdout.log" startupTimeLimit="3600"></httpPlatform>
  </system.webServer>
</configuration>

对于子应用程序,我必须删除 httpplatformhandler 处理程序以避免错误 "Cannot add duplicate collection entry of type 'add' with unique key attribute 'name' set to 'httpplatformhandler'"。

既然要用kestrel/httpplatformhandler,可不可以运行作为站点下的一个应用?

这个问题从 beta8 开始,在 RC1 中仍然是一个未解决的问题。参见 ASP.NET IIS Integration issue #14. "That fix is coming." says @davidfowl。 "This is a workaround until the fix is available. We're working with the httpPlatformHandler team to fix bugs found in beta8 and rc1."

解决方法是像这样映射 Startup.Configure 中的 IIS 应用程序路径:

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    app.Map("/MyAppPath", (myAppPath) => this.ConfigureMyAppPath(myAppPath, env));
}

public void ConfigureMyAppPath(IApplicationBuilder app, IHostingEnvironment env)
{
    // the actual Configure code
}