Created
January 12, 2012 19:53
-
-
Save shawnmclean/1602704 to your computer and use it in GitHub Desktop.
Custom user data for asp.net forms authentication
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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