【问题标题】:WIF 4.0 issue with deployment on load balanced environment在负载平衡环境中部署的 WIF 4.0 问题
【发布时间】:2025-12-25 20:10:16
【问题描述】:

我正在使用 WIF 4.0 来构建声明感知 RP 和 STS。现在我遇到了问题,因为我已经部署到我的生产环境,其中有多个服务器托管应用程序。由于某种原因,我得到了可怕的

[CryptographicException: Key not valid for use in specified state. ]

用户闲置一段时间后出错。我想知道是否有人有这方面的经验?使用机器密钥有帮助吗?在服务器上重置 IIS 时,我也看到了这个错误。我已将 LoadUserProfile 设置为 true。

【问题讨论】:

    标签: .net security iis wif claims-based-identity


    【解决方案1】:

    我认为您需要在 web.config 中指定与此类似的内容。此外,您需要在所有服务器上将机器密钥设置为相同。

        <system.identityModel>
      <identityConfiguration>
        <securityTokenHandlers> 
                    <remove type="System.IdentityModel.Tokens.SessionSecurityTokenHandler, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
            <add type="System.IdentityModel.Services.Tokens.MachineKeySessionSecurityTokenHandler, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </securityTokenHandlers> 
      </identityConfiguration>
    </system.identityModel>
    

    【讨论】:

    • 是的,很遗憾,该选项仅适用于 WIF 4.5。
    • 你可能是对的。另一方面,同样的方法也适用于旧版本。底线是您需要将 sessionsecuritytokenhandler 替换为使用固定密钥的处理程序。自己写这个并不难;特别是如果您可以查看 WIF 4.5 处理程序的代码。