Reputation: 11895
after user sign in. I save their username into the cookie.
FormsAuthentication.SetAuthCookie(userName, createPersistentCookie);
User has roles, "member", "staff", "manager"
for those page that only manager are allowed to enter. What I did right now is to query the DB using their username.
GetRoles(username)
That generates alot overhead, every time they visit a role protected page, I need to check the DB.
I am wondering if I can make SetAutheCookie to set a few values, not just the username.
What I did right now to combine username, roles in one string.
FormsAuthentication.SetAuthCookie(userName + "|" + role.tostring(), createPersistentCookie);
this definitely not the best solution.
Upvotes: 0
Views: 252
Reputation: 2041
The most-upvoted answer to this SO question provides an example of storing and retrieving roles in a forms authentication cookie: Store/assign roles of authenticated users
Upvotes: 1