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

那年仲夏 提交于 2019-12-06 12:39:59

问题


I'm writing an ASP.net application that uses Windows Identity Foundation. My ASP.net application uses claims-based authentication with passive redirection to a security token service. 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.

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. 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.

How do I remove the token so that the user can log in again and get a new token?


回答1:


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/

I also see that I can get handles to some other parts of the WIF framework this was, as well. It's definitely worth the read.




回答2:


Cookies are a bit strange. 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.

To "Delete" a cookie you have to set it's expiration date to the past.

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



来源:https://stackoverflow.com/questions/2180306/windows-identity-foundation-how-to-get-new-security-token-in-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!