错误 ASPCONFIG:无法打开 configSource 文件

error ASPCONFIG: Unable to open configSource file

我们的 .Net Framework 4.8 Web 应用程序突然开始在我们的团队城市构建服务器上生成以下构建时错误:

error ASPCONFIG: Unable to open configSource file ‘sessionState.config’.

我们的 web.config 引用了一个外部会话状态文件:

<sessionState configSource="sessionState.config" />

该项目正在积极开发中,但是最近没有对应用程序进行任何相关更改。我们最初认为这是构建服务器上的配置问题,但我们意识到,如果我们“发布”项目 勾选了“将所有输出合并到一个程序集中”。我们发布到本地文件以复制构建服务器上发生的事情。

将 sessionState.config 文件的构建操作从 None 修改为 Content 解决了问题,但这具有将我们的 sessionState.config 文件复制到部署的效果包裹,我们不想要。

我们花了很多时间试图调查这个问题,最后决定尝试卸载最近的 Microsoft 更新。这解决了它!我将此张贴在这里,希望它能至少为另一个人节省我们花费的时间。

这个特定的 2020 年 10 月 13 日更新是原因,但是,当我们搜索时没有找到它 https://support.microsoft.com/en-us/help/4578974/kb4578974-cumulative-update-for-net-framework

After you apply this October 13, 2020 Security and Quality Rollup for .NET Framework 4.8, some ASP.Net applications fail during precompilation. The error message that you receive will likely contain the words “Error ASPCONFIG.”

An invalid configuration state in either the "sessionState," "anonymouseIdentification," or "authentication/forms" sections of "System.web" configuration. This might occur during build-and-publish routines if configuration transformations leave the Web.config file in an intermediate state for precompilation.

注意他们在 anonymousIdentification

中的拼写错误

解决方案是将此 appSettings 密钥添加到您的 web.config

<configuration>
      <appSettings>
          <add key="aspnet:DisableAppPathModifier" value="true" />
     </appSettings>
</configuration>

文章指出,将值设置为“true”或“false”可以避免该问题。对于使用 cookie 作为会话状态 ID 的站点,建议将此值设置为“true”。

我们使用 cookie,因此将其添加到我们的 web.config 中并赋予其真值,并解决了问题。