views:

64

answers:

1

Hi

When checking for a users role in my custom authorize tag I am going to need a 3rd value. Like the built in stuff allows for this

"filterContext.HttpContext.User.Identity.Name;"

But this won't work for me since I will have many users with the same name. So I don't think this will help me when I have 10 with the same name and I have to pull up the GUID from them.

When doing my login stuff I use another field to tell the users apart.

So I am wondering can I show that 3rd field in the cookie(or however it does it with User.Identity.Name) and encrypt it with the cookie so it is safe and then do something like

"filterContext.HttpContext.User.Identity.UnquieField;"

A: 

Usually when I need to store multiple values into a cookie I create a lightweight class and use Json.NET to serialize/deserialize the class into the cookie's value. Therefore your cookie would look something like this:

user={UserName:bob123,Prefix:group1}

You can format it however you like, however. If Json is too heavy you could do something as simple as "user=bob123,group1".

The important thing is that your controller is going to need logic to parse/unparse the username and prefix from/to the cookie's value.

Tinister
How do I add it to the cookie? Is this what User.Identity.Name does? This parsing would happen for me in my customAttribute.
chobo2
I am using FormsAuthentication.SetAuthCookie by the way. So not sure do I have to make it another way to do this?
chobo2