0

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.

qinking126
  • 11,385
  • 25
  • 74
  • 124

1 Answers1

1

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

Community
  • 1
  • 1
Ian Gilroy
  • 2,031
  • 16
  • 14