System.Web.Security.FormsAuthentication.Encrypt returns null

Posted by Mustafakidd on Stack Overflow See other posts from Stack Overflow or by Mustafakidd
Published on 2010-04-21T20:31:20Z Indexed on 2010/04/21 20:33 UTC
Read the original article Hit count: 728

I'm trying to encrypt some userData to create my own custom IPrincipal and IIdentity objects using Forms authentication - I've serialized an object representing my logged in user to Json and created my FormsAuthentication ticket like so:

string user_item = GetJsonOfLoggedinUser();/*get JSON representation of my logged in user*/
System.Web.Security.FormsAuthenticationTicket ticket = new System.Web.Security.FormsAuthenticationTicket(1,
WAM.Utilities.SessionHelper.LoggedInEmployee.F_NAME + " " + 
WAM.Utilities.SessionHelper.LoggedInEmployee.L_NAME,
DateTime.Now, DateTime.Now.AddMinutes(30), false, user_item);
string encrypted_ticket = System.Web.Security.FormsAuthentication.Encrypt(ticket);
HttpCookie auth_cookie = new HttpCookie(
System.Web.Security.FormsAuthentication.FormsCookieName, encrypted_ticket);
Response.Cookies.Add(auth_cookie);

However, the string encrypted_ticket is always null. Is there a limit on the length of the user_item string?

Thanks Mustafa

© Stack Overflow or respective owner

Related posts about formsauthentication

Related posts about ASP.NET