Creating a custom UserState object

The default UserState object contains the following properties:

  • Name
  • Email
  • UserId
  • UserIdInt
  • IsAdmin
  • SecurityToken

The name is a display name like "Rick Strahl" while UserId can be an identifier for the user or correlation to a user record in a database. The SecurityToken is an otionally generated unique value that can be used for token based authentication when coordinating with services.

If you want to extend these basic properties and add your own, you can simply subclass userstate:

public class AppUserState : UserState
{
     public string NickName {get; set; }
}

Any properties you add become part of the stored userstate passed on the Forms Auth cookie.

Note that you don't want to create a lot of properties here to avoid bloating the Forms Auth cookie size. Only store necessary values that you might need to display user information in sign in/sign out ui's etc. Keep it lean!


© West Wind Technologies, 1996-2016 • Updated: 12/19/15
Comment or report problem with topic