Click to See Complete Forum and Search --> : Formsauthentication cookie problem


shuvo
July 20th, 2006, 12:52 PM
My OS is XP with service pack 2 installed and Cookies enabled. I am trying to implement Role based security here ...just as the code provided in MSDN.
I am creating a formsauthenticate cookie with the encrypted ticket.So all my user and roles information is stored in my cookie.Problem is when i redirect from the login page and the Application_AuthenticateRequest is invoked.

protected void Application_AuthenticateRequest(object o, EventArgs e)
{
HttpCookie cookie = Request.Cookies[FormsAuthentication.FormsCookieName];
if(cookie != null)
{
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(cookie.Value);
string[] role = new string[]{ticket.UserData};
Context.User = new GenericPrincipal(new FormsIdentity(ticket), role);
}

The cookie is not NULL.But I always get the role =" ", which means the Ticket.UserData is not getting stored in the cookie at all and I am getting role="".I have tried both persistent and nonpersistent cookie.But its the same.can u tell what could be the reason that cookie value is not getting stored.As long as i am in the login page..the values are there, i Have checked it.

Rohit Kukreti
July 20th, 2006, 01:57 PM
Are u adding the ticket data as some char delimited string... then u might need to split the data before assiging it to an array. If not then paste the complete code (how u add the date, etc.)

shuvo
July 21st, 2006, 02:39 AM
Yes i used char delimeter for the string.But the problem is not with the string here.The problem is my data is not available in the cookies,ticket.userdata returns "".I am getting this ticket by

FormsAuthentication.Decrypt("Cookie.Value)
This user data should contain the Role defining string...but it is containing a NULL.It contains data while i m in the login page,but after i redirect and movie into the authenticateRequest even..i don't know why is it becoming null.