在带有 VS 2022 和 IIS Express 的 .Net 6.0 应用程序中调试时,在一个站点下配置的几个应用程序无法始终如一地工作

问题描述 投票:0回答:0

上下文:Windows 2016、VS 2022 - 17.5.1(截至目前的最新版本,2023 年 3 月 13 日)、使用 Giraffe 框架的 .Net 6.0 F# Web 应用程序、IIS Express 10(产品版本 10.0.25095.1000)。

注意:我在管理员模式下运行 VS 2022。

当我使用 IIS Express 在 VS 2022 中以开发模式运行应用程序时,我想将 /Scripts 路径重定向到另一个包含大量 JavaScript、css、图像等文件的文件夹:

d:\webapps\webroot\Scripts
.

这是我在

applicationhost.config
文件中的内容:

        <applicationPools>
            <add name="Clr4IntegratedAppPool" managedRuntimeVersion="v4.0" managedPipelineMode="Integrated" CLRConfigFile="%IIS_USER_HOME%\config\aspnet.config" autoStart="true" />
            <add name="Clr4ClassicAppPool" managedRuntimeVersion="v4.0" managedPipelineMode="Classic" CLRConfigFile="%IIS_USER_HOME%\config\aspnet.config" autoStart="true" />
            <add name="Clr2IntegratedAppPool" managedRuntimeVersion="v2.0" managedPipelineMode="Integrated" CLRConfigFile="%IIS_USER_HOME%\config\aspnet.config" autoStart="true" />
            <add name="Clr2ClassicAppPool" managedRuntimeVersion="v2.0" managedPipelineMode="Classic" CLRConfigFile="%IIS_USER_HOME%\config\aspnet.config" autoStart="true" />
            <add name="UnmanagedClassicAppPool" managedRuntimeVersion="" managedPipelineMode="Classic" autoStart="true" />
            <add name="MyApp AppPool" managedRuntimeVersion=""/>
            <add name="MyApp AppPool 2" autoStart="true" />
            <applicationPoolDefaults managedRuntimeVersion="v4.0">
                <processModel />
            </applicationPoolDefaults>
        </applicationPools>
...
   <sites>
         <site name="MyApp" id="2">
                <application path="/" applicationPool="MyApp AppPool">
                   <virtualDirectory path="/" physicalPath="D:\webapps\webroot" />
                </application>
                <application path="/MyApp" applicationPool="MyApp AppPool 2">
                    <virtualDirectory path="/" physicalPath="D:\webapps\MyApp\src\MyApp" />
                </application>
                <bindings>
                    <binding protocol="http" bindingInformation="*:51582:localhost" />
                    <binding protocol="https" bindingInformation="*:44339:localhost" />
                </bindings>
            </site>
   </sites>

我遇到的问题是 /Scripts 下的任何请求都会返回 404。

您在上面看到的配置曾经在我拥有的以前版本的 VS 2022 中工作。不再。也许是升级到 17.5.1 导致它崩溃了——我在星期四升级了 VS 2022。更糟糕的是,今天,它工作了一段时间,然后就停止工作了,这不是一个好兆头。我当然重启了 VS 2022,但我没有重启 Windows。我想我不应该这样做。我有很多我使用的应用程序是开放的。

以下是我注意到的一些事情:

  • 如果我使用以下命令从命令行运行 IIS Express:
    "C:\Program Files\IIS Express\iisexpress.exe"  /config:"D:\webapps\MyApp\src\.vs\MyApp\config\applicationhost.config" /site:"MyApp"
    一切正常(只要我之前设置了
    set ASPNETCORE_ENVIRONMENT=Development
    set LAUNCHER_PATH=D:\webapps\MyApp\src\MyApp\bin\Debug\net6.0\MyApp.exe
    .
  • 应用程序网址是
    htts://localhost:44339/MyApp/
    .
  • VS 2022 使用以下命令启动 IIS Express:
    "C:\Program Files\IIS Express\iisexpress.exe"  /config:"D:\webapps\MyApp\src\.vs\MyApp\config\applicationhost.config" /site:"MyApp" /apppool:"MyApp AppPool 2"
    。注意
    /apppool
    论点。它没有记录:https://learn.microsoft.com/en-us/iis/extensions/using-iis-express/running-iis-express-from-the-command-line。我有预感,这个参数是导致问题的原因。也许它告诉 IIS Express 启动
    MyApp AppPool 2
    ,而它忽略了另一个池
    MyApp AppPool
    。但我在这里可能是错的,因为我也尝试为
    autoStart=true
    池添加
    MyApp AppPool
    属性但它没有用。我将
    applicationPool="Clr4IntegratedAppPool"
    设置为
    application path="/"
    但这也不起作用。
  • 调试属性对话框(在 IIS Express 下拉菜单下可用)-> IIS Express 配置文件有一个命令行参数框,理论上您可以在其中指定不同的参数,但是,我在此处设置的任何内容都不会覆盖 VS 2022 自动设置的参数。

所以,在这一点上我很难过。当我在 VS 2022 中调试应用程序时,您对如何使此配置正常工作有什么建议或想法吗?

TIA

更新:我重启了windows - 重启后问题仍然存在。

.net-6.0 visual-studio-2022 iis-express iis-express-10
© www.soinside.com 2019 - 2024. All rights reserved.