IIS中的ASP.NET Core应用程序内的虚拟目录 [英] Virtual directory inside of ASP.NET Core app in IIS

查看:2461
本文介绍了IIS中的ASP.NET Core应用程序内的虚拟目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个使用ASP.NET Core 1.0 RC1并在IIS上托管的应用程序。它工作正常。现在我们有静态内容,可以在文件共享上获得,并且应该可以从应用程序访问。

We have an application using ASP.NET Core 1.0 RC1 and hosted on IIS. It works fine. Now we have static content, that is available on a file share and should be accessible from the application.

在ASP.NET 5之前,我们在IIS中添加了一个虚拟目录,可以轻松访问共享内容。使用我们托管的ASP.NET 5应用程序,遗憾的是这似乎不起作用。我们只是在尝试访问静态内容时得到 404

Before ASP.NET 5, we added a virtual directory in IIS and could access the shared content easily. With our hosted ASP.NET 5 application, this unfortunately doesn't seem to work. We just get a 404 back when trying to access the static content.

我们的应用程序使用 app.UseIISPlatformHandler() app.UseStaticFiles(),但这不起作用。我们发现我们可以使用 app.UseFileServer()和自定义 FileServerOptions 来获得所需的行为,但我们很好奇如果它也可以用正常的旧方式在IIS中添加虚拟目录。

Our application is using app.UseIISPlatformHandler() and app.UseStaticFiles(), but this doesn't work. We discovered that we could use app.UseFileServer() with custom FileServerOptions to get the desired behavior, but we are curious if it's also possible with the normal "old" way of adding a virtual directory in IIS.

推荐答案

我今天遇到了这个问题,并最终设法解决它。诀窍(对我来说,可能并不适合所有人)确保在子应用程序中禁用 aspNetCore 处理程序,并在主(ASP.NET Core)应用程序中启用。

I encountered this problem today, and finally managed to fix it. The trick (for me, probably not for everyone) is making sure the aspNetCore handler is disabled in the sub-application and enabled in the main (ASP.NET Core) application.

我的ASP.NET核心应用程序有一个基本的Web.config

My ASP.NET Core app has a basic Web.config

<configuration>
  <system.webServer>
    <handlers>
        <add name="aspNetCore" path="*" verb="*" type="" modules="AspNetCoreModule" scriptProcessor="" resourceType="Unspecified" requireAccess="Script" allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
    </handlers>
    <aspNetCore processPath="dotnet" arguments=".\bin\Debug\netcoreapp2.0\myapp.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" />
  </system.webServer>
</configuration>

并且在IIS中添加为子应用程序的应用程序

and the application added as a sub-application in IIS has

<configuration>
  <!-- removed -->
  <system.webServer>
      <handlers>
          <remove name="aspNetCore" />
       </handlers>
  </system.webServer>
</configuration>

这篇关于IIS中的ASP.NET Core应用程序内的虚拟目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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