StartSTS 和带有负载均衡器的依赖方

发布于 2024-12-11 03:15:53 字数 1289 浏览 0 评论 0原文

由于需要在负载均衡器上运行我的网站,我不得不用以下内容替换会话令牌处理程序。

public class WebFarmSessionSecurityTokenHandler : SessionSecurityTokenHandler
{
    public WebFarmSessionSecurityTokenHandler(X509Certificate2 protectionCertificate)
        : base(CreateRsaTransforms(protectionCertificate))
    { }

    private static ReadOnlyCollection<CookieTransform> CreateRsaTransforms
      (X509Certificate2 protectionCertificate)
    {
        var transforms = new List<CookieTransform>() 
                        { 
                            new DeflateCookieTransform(), 
                            new RsaEncryptionCookieTransform(protectionCertificate),
                            new RsaSignatureCookieTransform(protectionCertificate),
                        };

        return transforms.AsReadOnly();
    }
}

然后我修改了 web.config 如下。

<microsoft.identityModel>
  <service>
...
    <securityTokenHandlers>
      <clear />
      <add type="MyAssembly.WebFarmSessionSecurityTokenHandler, MyAssembly"/>
    </securityTokenHandlers>
...
  </service>
</microsoft.identityModel>

完成此操作后,我希望我的依赖方无论访问哪个节点或哪个盒子发起身份验证,都能正常运行。

我当前收到以下信息:SecurityTokenHandler 未注册来读取安全令牌。

有什么想法吗?

I've had to replace the session token handler with the following, due to a requirement of running my site on load balancers.

public class WebFarmSessionSecurityTokenHandler : SessionSecurityTokenHandler
{
    public WebFarmSessionSecurityTokenHandler(X509Certificate2 protectionCertificate)
        : base(CreateRsaTransforms(protectionCertificate))
    { }

    private static ReadOnlyCollection<CookieTransform> CreateRsaTransforms
      (X509Certificate2 protectionCertificate)
    {
        var transforms = new List<CookieTransform>() 
                        { 
                            new DeflateCookieTransform(), 
                            new RsaEncryptionCookieTransform(protectionCertificate),
                            new RsaSignatureCookieTransform(protectionCertificate),
                        };

        return transforms.AsReadOnly();
    }
}

I then amended the web.config as follows.

<microsoft.identityModel>
  <service>
...
    <securityTokenHandlers>
      <clear />
      <add type="MyAssembly.WebFarmSessionSecurityTokenHandler, MyAssembly"/>
    </securityTokenHandlers>
...
  </service>
</microsoft.identityModel>

My hope after doing this was that my relying party would function no matter what node it was accessing or what box initiated the authenication.

I'm currently getting the following : A SecurityTokenHandler is not registered to read security token.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橘和柠 2024-12-18 03:15:53
void onServiceConfigurationCreated(object sender, ServiceConfigurationCreatedEventArgs e)
        {
            List<CookieTransform> sessionTransforms = new List<CookieTransform>(new CookieTransform[] 
            { 
                new DeflateCookieTransform(), 
                new RsaEncryptionCookieTransform(e.ServiceConfiguration.ServiceCertificate),
                new RsaSignatureCookieTransform(e.ServiceConfiguration.ServiceCertificate)
            });

            SessionSecurityTokenHandler sessionHandler = new SessionSecurityTokenHandler(sessionTransforms.AsReadOnly());
            e.ServiceConfiguration.SecurityTokenHandlers.AddOrReplace(sessionHandler);
        }

上面的内容需要放在global.asax文件中。在应用程序启动中连接以下事件。

FederatedAuthentication.ServiceConfigurationCreated += onServiceConfigurationCreated;

我不再需要 WebFarmSessionSecurityTokenHandler 或配置更改来将其插入。

void onServiceConfigurationCreated(object sender, ServiceConfigurationCreatedEventArgs e)
        {
            List<CookieTransform> sessionTransforms = new List<CookieTransform>(new CookieTransform[] 
            { 
                new DeflateCookieTransform(), 
                new RsaEncryptionCookieTransform(e.ServiceConfiguration.ServiceCertificate),
                new RsaSignatureCookieTransform(e.ServiceConfiguration.ServiceCertificate)
            });

            SessionSecurityTokenHandler sessionHandler = new SessionSecurityTokenHandler(sessionTransforms.AsReadOnly());
            e.ServiceConfiguration.SecurityTokenHandlers.AddOrReplace(sessionHandler);
        }

The above needs to be placed inside the global.asax file. With the following event hooked up in the application start.

FederatedAuthentication.ServiceConfigurationCreated += onServiceConfigurationCreated;

I no longer required the WebFarmSessionSecurityTokenHandler or the config changes to slot it in.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文