Claims without roles?

I am trying to understand the authentication and authorization mechanism of ASP.NET. I realized what a requirement and what a role. In almost every related blog post or question here, he advises using claims and avoiding roles. I am confused at this moment. How can I use claims without roles? (I usually assign roles to users after they register.)

Any help is appreciated.

thank

+4
source share
2 answers

Roles are also claims; claims are more general.

In almost every related blog post or question here, he advises using assertions and avoiding roles.

, , " ".

" ". , , , , .

, ClaimsPrincipal Role, ASP.NET , , - WebForms, MVC .

, , , .

http://www.wiktorzychla.com/2014/11/forms-authentication-revisited-for-net.html

, ,

var identity = new ClaimsIdentity( "custom" );
identity.AddClaim( new Claim( ClaimTypes.Name, txtLogin.Text ) );
identity.AddClaim( new Claim( ClaimTypes.Role, "admin" ) );

var principal = new ClaimsPrincipal( identity );

// write the principal to cookie  

, " 18 " " , ". "", .

,

https://msdn.microsoft.com/en-us/library/system.security.claims.claimsauthorizationmanager(v=vs.110).aspx

+4

. , , , , ,

, , AuthorizeAttribute:

ASP.NET Identity

ASP.NET ASP.NET

+1

All Articles