1

最近,我开始在现有的 Web 应用程序上使用基于声明的身份验证。一切正常,但为了更好地处理 SessionSecurity 令牌的到期,我想使用滑动到期。

但是,我无法为 SecurityTokenReceived 事件注册事件处理程序。

我的处理程序方法在 Global.asax.cs 中定义如下:

protected void SessionAuthenticationModule_SessionSecurityTokenReceived(object sender, SessionSecurityTokenReceivedEventArgs e) { ... }

但是,当在同一个文件的 Application_Start 中注册此处理程序方法时,如下所示:

FederatedAuthentication.WSFederationAuthenticationModule.SecurityTokenReceived += SessionAuthenticationModule_SessionSecurityTokenReceived;

Visual Studio 响应不存在与委托 System.EventHandler 匹配的 SessionAuthenticationModule_SessionSecurityTokenReceived 的重载。

我在 web.config 部分有以下设置:

<securityTokenHandlers>
    <add type="Microsoft.IdentityModel.Tokens.SessionSecurityTokenHandler, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
      <sessionTokenRequirement lifetime="0:02" />
    </add>
  </securityTokenHandlers>

我已经阅读了 MSDN 上的一些可用文档,但我不明白为什么不接受事件处理程序。有人可以帮忙吗?

4

2 回答 2

3

FederatedAuthentication.WSFederationAuthenticationModule.SecurityTokenReceived 期望使用SecurityTokenReceivedEventArgs而不是 SessionSecurityTokenReceivedEventArgs 的方法(正如我的 VS 所说)。尝试将您的代码更改为:

protected void SessionAuthenticationModule_SessionSecurityTokenReceived(object sender, SecurityTokenReceivedEventArgs e)
于 2013-04-08T10:25:57.650 回答
3

感谢 Danila Polevshikov 的回答,我注意到了我的错误。解决方法如下:

在 Application_Start 方法中,事件处理程序应该是:

FederatedAuthentication.SessionAuthenticationModule.SessionSecurityTokenReceived += SessionAuthenticationModule_SessionSecurityTokenReceived;

我需要有 SessionSecurityTokenReceivedArgs 参数,因为我需要重新发出一个 cookie。

于 2013-04-08T12:06:53.420 回答