FormsAuthenticationTicket looses UserData

D

dev648237923

Upon logon I create a ticket and put some userdata in it:
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
3, //Version
tUsername.Text, //Username
DateTime.Now, //Issue time
DateTime.Now.AddHours(1), //Expires every hour
false, //Don't persist cookie
"test data" //User_SecureID
);
//Hash the cookie for transport
string hash = FormsAuthentication.Encrypt(ticket);
cookie = new HttpCookie( FormsAuthentication.FormsCookieName, hash);
Response.Cookies.Add(cookie);

***Later on another aspx page I want to read that userdata but it alweays is
empty???
if (HttpContext.Current.User != null)
{

if (HttpContext.Current.User.Identity.IsAuthenticated)
{
if (HttpContext.Current.User.Identity is FormsIdentity)
{
FormsIdentity id = (FormsIdentity)HttpContext.Current.User.Identity;
FormsAuthenticationTicket ticket = id.Ticket;
string userData = ticket.UserData;
}
}
}

Any ideas on fixing this greatly appretiated!
 
W

Walter Wang [MSFT]

Hi,

I created a simple web site using your code and it seems working correctly
on my side. I simply put the ticket creation code in login.aspx and in
default.aspx I can read the cookie's userData correctly.

Could you please confirm this also doesn't work on your side using a simple
web site? or maybe it's an environment specific issue.

Would you please create a more complete reproducible project and send it to
me? Thanks.


Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

dev648237923

Hi --

I also was able to get a simple project working so I think it must be an
environmental issue on this project. I will investigate further and post if
I find out what caused it. Thank you for you help and confirming tha the
code I am using is correct!
 
W

Walter Wang [MSFT]

Hi,

Thanks for the follow-up. I'll be standing by when you find further
information on this issue.


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top