English 中文(简体)
Windows Identity Foundation:如何在ASP.net中获取新的安全令牌
原标题:Windows Identity Foundation: How to get new security token in ASP.net

我正在编写一个使用Windows身份基础的ASP.net应用程序。我的ASP.net应用程序使用基于声明的身份验证,通过被动重定向到安全令牌服务进行身份验证。这意味着当用户访问应用程序时,他们会自动重定向到安全令牌服务,从而获得一个安全令牌,该令牌可以将其身份识别给应用程序。

在ASP.net中,安全令牌是以cookie的形式存储的。

我想在我的应用程序中添加一个可以点击的东西,以删除 cookie 并将用户重定向到安全令牌服务以获取新令牌。简而言之,使注销和重新登录为另一个用户变得容易。我设法在代码中删除包含令牌的 cookie,但它仍然存在。

我怎样可以移除令牌让用户可以重新登录并且获取新的令牌?

最佳回答

我找到了解决办法。简略地说:

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

点击此处获取更多信息:http://garrettvlieger.com/blog/2010/03/refreshing-claims-in-a-wif-claims-aware-application/

我也发现我可以获取到WIF框架的一些其他部分的句柄。这确实值得一读。

问题回答

饼干有点奇怪。它们由浏览器管理,没有“方法”可以删除它们。仅仅从服务器端的Request或Response对象中删除它们并不能将它们从客户端浏览器中删除。

要“删除”Cookie,您必须将其过期日期设置为过去。

请见:http://msdn.microsoft.com/zh-cn/library/ms178195.aspx





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签