加入声称窗体身份验证在asp

加入声称窗体身份验证在asp

本文介绍了加入声称窗体身份验证在asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力,它使用Windows Azure的表作为数据存储,为用户information.I有一个类做表的插入和创建和处理其他的东西一个asp.net应用程序。当我看到一个用户已经是present我要发出使用类似

I have been working on a asp.net application which uses windows azure tables as data storage for users information.I have a class which does the insertion and creation of tables and handles other stuff. When I see that a user is already present I want to issue a authentication token using something like

FormsAuthentication.SetAuthCookie(user,true)

和我也想添加用户的要求,我从Windows Azure的表存储了,所以我可以在以后使用类似

and I also want to add the user's claims that I got from the windows azure table storage so I can read them later using something like

ClaimsPrincipal claimsPrincipal = Page.User as ClaimsPrincipal;

可有人请建议我如何实现这一目标?我完成了这个自定义应用程序的其他部分,但不是很清楚如何让这部分的工作。

Can someone please suggest me how to achieve this? I finished the other parts of this custom app but not very clear how to make this part work.

感谢

推荐答案

几乎一样简单,用SessionAuthenticationModule的帮助。

This is almost as simple, with the help of the SessionAuthenticationModule.

SessionAuthenticationModule sam =
    (SessionAuthenticationModule)
    this.Context.ApplicationInstance.Modules["SessionAuthenticationModule"];

IClaimsPrincipal principal =
   new ClaimsPrincipal( new GenericPrincipal( new GenericIdentity( txtUserName.Text ), null ) );

// create any userdata you want. by creating custom types of claims you can have
// an arbitrary number of your own types of custom data
principal.Identities[0].Claims.Add( new Claim( ClaimTypes.Email, "[email protected]" ) );
principal.Identities[0].Claims.Add( new Claim( ClaimTypes.UserData, ReallyLongUserData ) );

var token =
  sam.CreateSessionSecurityToken(
     principal, null, DateTime.Now, DateTime.Now.AddMinutes( 20 ), false );
sam.WriteSessionTokenToCookie( token );

Response.Redirect( this.Context.Request.QueryString["ReturnUrl"] );

全部文章,其中还包括的web.config 条目:

这篇关于加入声称窗体身份验证在asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 08:24