Unable to cast object of type 'System.Security.Principal.GenericIdentity' to type 'System.Web.Securi

K

kroyce

I completed the How To on using Forms Authentication with Active
Directory and am receiving an error when casting Current.User to
FormsIdentity object. I can't find my error nor can I find anything
through Google, MSDN or KB on the issue. This leads me to believe it
is my issue and I need some help if at all possible. The error
message I receive is:

Unable to cast object of type
'System.Security.Principal.GenericIdentity' to type
'System.Web.Security.FormsIdentity'.

My c# code looks like the following and I am using ASP.Net 2.0:
lblName.Text = "Hello " + Context.User.Identity.Name + ".";
lblAuthType.Text = "You were authenticated using " +
Context.User.Identity.AuthenticationType + ".";
FormsIdentity id =
(FormsIdentity)HttpContext.Current.User.Identity;
FormsAuthenticationTicket ticket = id.Ticket;
lblCookieUserName.Text = ticket.Name;
lblCookieData.Text = ticket.UserData;

Context.User.Identity.Name works great as does
Context.User.Identity.AuthenticationType.

The offending piece of code is:
FormsIdentity id =
(FormsIdentity)HttpContext.Current.User.Identity;

Any help or insight that you can provide would be very much
appreciated.
 

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,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top