Can I use user.IsInRole without using membership?

I use forms authentication and I would like to use roles, can I somehow establish a user role without membership?

+3
source share
4 answers

An easy way to do this is to keep the list of roles in the authentication ticket for user authentication. Then, for each request ( Application_AuthenticateRequestthe global.asax file method), you retrieve the roles, add them to the object, GenericPrincipaland set the property Httpcontext.User.

Yours User.IsInRole("role")and [AuthorizeAttribute(Roles="role")]will work as usual.

For more on how to do this, see this answer .

+5
source

" ASP.NET"?

, , / . . , /.

+1

, .

, ( , ), - ( , ).

MSDN:

:

. , , .

+1

.

Principal ( IsInRole) Identity.
, (HttpApplication.Context.User) .
. Authorize .

+1

Source: https://habr.com/ru/post/1733223/


All Articles