FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(2, username, DateTime.Now,//Cookie Issue Date DateTime.Now.AddMinutes(30),//Expire Date isPersistent,//Is cookie Persistent or not userData,//Custom data here we store current authenticated user's role FormsAuthentication.FormsCookiePath); // Encrypt the ticket. string encTicket = FormsAuthentication.Encrypt(ticket); // Create the cookie with authenticated ticket. Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));
How to access this role information while request in other system?
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(FormsAuthentication.FormsCookieName); String data = ticket.UserData; String roles = data.Split(',');//If you have store multiple role or data with Comma value
As from above code we can decrypt authenticated cookie and extract all information we have set like Username,Cookie Issue Date, Expire Date,Userdata etc. As Previously we have store role information in userdata property we can retrieve User's Role value and check weather user have valid access right or not.