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

Discussion in 'ASP .Net Security' started by kroyce@ups.edu, May 1, 2007.

  1. Guest

    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.
     
    , May 1, 2007
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page