Cast exception w FormsAuthentication

N

news.microsoft.com

I have a small ASPX app I have created and decided to roll my own Forms
Authentication. Now I take the user name, password and domain and created an
encrypted foms authentication ticket. In the ticket I put some info in the
userdata property. On a different page after authetication I want to accsess
that field. I found a couple of examples, one is like
lblLogin.Text = ((FormsIdentity)User.Identity).Ticket.UserData;

This throws an exception saying cast is not valid. I've looked at this where
the GenericPrincipal is created in the Globalasax file and I can see the
string data in the UserData, does anyone have any idea?
 
C

Chris Jackson

Make sure you are casing the proper unary expression:

....((FormsIdentity)(User.Identity)).Ticket.UserData;
 

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

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top