I am working with Visual Studio 2019 (.NET 4.7). My project is an ASP.NET MVC web app, without Microsoft Identity.
I try to implement the mechanism of authentication and authorization because I want to use the attributes like [Authorize(Roles = "admins")]
on my controllers/actions.
I don’t want to use Microsoft Identity, EF and OWIN.
I started to implement form authentication, and I can get everywhere in my code the current user name with User.Identity.Name
which has the same value as FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe)
used in the login process.
I can store the roles in the field UserData
inside the FormsAuthentication
ticket.
Now, I want to implement the roles in order to activate the [Authorize]
attributes and to use the function User.IsInRole("***")
everywhere in my code.
Can someone help me ?