Skip to content

Instantly share code, notes, and snippets.

@shawnmclean
Created January 12, 2012 19:53
Show Gist options
  • Save shawnmclean/1602704 to your computer and use it in GitHub Desktop.
Save shawnmclean/1602704 to your computer and use it in GitHub Desktop.
Custom user data for asp.net forms authentication
/// <summary>
/// Extra user custom data
/// </summary>
public class UserIdentity
{
public int UserId { get; set; }
public string Username { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
[Serializable]
public class CustomIdentity : IIdentity
{
private System.Web.Security.FormsAuthenticationTicket ticket;
private UserIdentity user;
public CustomIdentity(System.Web.Security.FormsAuthenticationTicket ticket)
{
this.ticket = ticket;
//deserialize the userdata back into user identity
user = JsonSerializer.DeserializeFromString<UserIdentity>(ticket.UserData);
}
public string AuthenticationType
{
get { return "Custom"; }
}
public bool IsAuthenticated
{
get { return ticket != null; }
}
public string Username
{
get { return user.Username; }
}
public string FirstName
{
get { return user.FirstName; }
}
public string LastName
{
get { return user.LastName; }
}
public string Name
{
get { return user.Username; }
}
public int UserId
{
get { return user.UserId; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment