qinking126
qinking126

Reputation: 11895

asp.net mvc3 form authentication, is it possible to set multi AuthCookies?

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

Answers (1)

Ian Gilroy
Ian Gilroy

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

Related Questions