FormsAuthentication.Encrypt returns null
I was writing some ASP.NET authentication code last night and was trying to encrypt an authentication ticket using FormsAuthentication.Encrypt(). However, it kept returning null. I banged my head against the wall for about an hour and then went home. As so often happens, I came in in the morning and spotted the problem immediately: the authentication ticket's user data was null. Doh! I had only put null in there for test purposes!
C#:
-
FormsAuthenticationTicket authTicket =
-
new FormsAuthenticationTicket(
-
1, // version
-
"stu@me.com", // email
-
DateTime.Now, // creation
-
DateTime.Now.AddMinutes(60),// Expiration
-
false, // Persistent
-
null); // User data (TICKET WON'T BE ENCRYPTED IF THIS IS NULL)
-
-
string encryptedTicket = FormsAuthentication.Encrypt(authTicket);

December 25th, 2007 at 19:31
Thanks Stuart - I was banging my head on this for about 30 minutes before finding this post…