2013-04-08 124 views
0

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

但是,我很难注册SecurityTokenReceived事件的事件处理程序。

我的处理方法是指像这样在Global.asax.cs中:

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

但在Application_Start像这样注册此处理方法将同一文件的:

FederatedAuthentication.WSFederationAuthenticationModule.SecurityTokenReceived += SessionAuthenticationModule_SessionSecurityTokenReceived; 

视觉Studio响应SessionAuthenticationModule_SessionSecurityTokenReceived没有与委托System.EventHandler匹配的重载。

我在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上的可用文档,但我不明白为什么事件处理程序是不能接受的。任何人都可以协助吗?

回答

3

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

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

FederatedAuthentication.SessionAuthenticationModule.SessionSecurityTokenReceived += SessionAuthenticationModule_SessionSecurityTokenReceived; 

我需要有SessionSecurityTokenReceivedArgs的说法,因为我需要重新发出一个cookie。

3

FederatedAuthentication.WSFederationAuthenticationModule.SecurityTokenReceived预计法SecurityTokenReceivedEventArgs而不是SessionSecurityTokenReceivedEventArgs(如我的VS表示)。尝试将您的代码更改为:

protected void SessionAuthenticationModule_SessionSecurityTokenReceived(object sender, SecurityTokenReceivedEventArgs e) 
+0

非常感谢Danila,您指出了我犯的错误。我已经回答了我自己的问题,但投了你的答案,因为它也帮助我 – Raybiez 2013-04-08 12:08:14

相关问题