Link to home
Start Free TrialLog in
Avatar of derekclee
derekclee

asked on

Error checking type for HttpContext.Current.User.Identity

This code was converted from VB.NET and I'm getting the following errors:

System.Web.HttpContext.Current' is a 'property' but is used like a 'type'
and
Cannot implicitly convert type 'System.Security.Principal.IIdentity' to 'System.Web.Security.FormsIdentity'. An explicit conversion exists (are you missing a cast?)
public void doAuthentication()
    {
        if (HttpContext.Current.User != null)
        {
            if (HttpContext.Current.User.Identity.IsAuthenticated)
            {
                if (typeof (HttpContext.Current.User.Identity) is FormsIdentity)
                {
                    FormsIdentity id = HttpContext.Current.User.Identity;
                    FormsAuthenticationTicket ticket = id.Ticket;
                    string strUserData = ticket.UserData;
                    string[] strRoles = strUserData.Split(',');
                    HttpContext.Current.User = new GenericPrincipal(id, strRoles);
                }
            }
        }
    }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of GuitarRich
GuitarRich
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of derekclee
derekclee

ASKER

Apologies for late acceptance. The answer did the trick. Many thanks.