简体   繁体   English

Windows Identity Foundation:如何在ASP.net中获取新的安全令牌

[英]Windows Identity Foundation: How to get new security token in ASP.net

I'm writing an ASP.net application that uses Windows Identity Foundation. 我正在编写一个使用Windows Identity Foundation的ASP.net应用程序。 My ASP.net application uses claims-based authentication with passive redirection to a security token service. 我的ASP.net应用程序使用基于声明的身份验证和对安全令牌服务的被动重定向。 This means that when a user accesses the application, they are automatically redirected to the Security Token Service where they receive a security token which identifies them to the application. 这意味着,当用户访问应用程序时,他们会自动重定向到“安全令牌服务”,在此他们会收到一个安全令牌,该令牌会向应用程序标识他们。

In ASP.net, security tokens are stored as cookies. 在ASP.net中,安全性令牌存储为cookie。

I want to have something the user can click on in my application that will delete the cookie and redirect them to the Security Token Service to get a new token. 我希望用户可以在我的应用程序中单击一些东西,这将删除cookie并将其重定向到Security Token Service以获取新的令牌。 In short, make it easy to log out and log in as another user. 简而言之,可以轻松注销并以其他用户身份登录。 I try to delete the token-containing cookie in code, but it persists somehow. 我尝试删除代码中包含令牌的cookie,但是它以某种方式持续存在。

How do I remove the token so that the user can log in again and get a new token? 如何删除令牌,以便用户可以再次登录并获取新令牌?

I found the solution. 我找到了解决方案。 To put it succinctly: 简而言之:

  Dim smartWsFederationAuthenticationModule As _ Microsoft.IdentityModel.Web.WSFederationAuthenticationModule = _ HttpContext.Current.ApplicationInstance.Modules("WSFederationAuthenticationModule") smartWsFederationAuthenticationModule.SignOut(True) 

See here for more information: http://garrettvlieger.com/blog/2010/03/refreshing-claims-in-a-wif-claims-aware-application/ 详情请参阅此处: http : //garrettvlieger.com/blog/2010/03/refreshing-claims-in-a-wif-claims-aware-application/

I also see that I can get handles to some other parts of the WIF framework this was, as well. 我还看到,我也可以处理WIF框架的其他部分。 It's definitely worth the read. 绝对值得一读。

Cookies are a bit strange. Cookies有点奇怪。 They are managed by the browser and there is no "Method" to delete them. 它们由浏览器管理,没有“方法”可以删除它们。 Just deleting them from the Request or Response objects on the server side does not remove them from the browser on the client side. 仅仅从服务器端的Request或Response对象中删除它们并不会从客户端的浏览器中删除它们。

To "Delete" a cookie you have to set it's expiration date to the past. 要“删除” cookie,您必须将其过期日期设置为过去。

See: http://msdn.microsoft.com/en-us/library/ms178195.aspx 请参阅: http//msdn.microsoft.com/en-us/library/ms178195.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Windows Identity Foundation将某人登录到ASP.net应用程序 - Using Windows Identity Foundation to log someone in to an ASP.net application ASP.NET身份-令牌 - ASP.NET Identity - Token ASP.Net 身份 2 与 windows 服务和 MVC,令牌问题 - ASP.Net identity 2 with windows service and MVC, Token issues Windows Identity Foundation安全令牌服务设置cookie超时 - Windows Identity Foundation Security Token Service setting cookie timeouts Windows Identity Foundation安全令牌服务无法保持登录状态 - Windows Identity Foundation Security Token Service can't stay logged in 如何批量更新用户的安全戳? Asp.net身份 - How to update security stamp of users in bulk? Asp.net Identity 如何为asp.net标识创建安全戳记值(IUserSecurityStampStore) - How to create a security stamp value for asp.net identity (IUserSecurityStampStore) 如何从ASP.NET Identity 2.0中的PasswordReset令牌获取UserId? - How to get UserId from a PasswordReset token in ASP.NET Identity 2.0? ASP.NET身份外部登录-如何获取用于API调用的Google令牌? - ASP.NET Identity External Login - How to get Google Token for API calls? 如何在ASP.NET身份电子邮件确认中修复“无效令牌” - How to fix 'Invalid Token' on ASP.NET Identity Email Confirmation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM