UserState Class
User information container that can easily 'serialize' to a string and back, that can be stored easily in single cookie or in a single User Claim value.
Meant to hold basic logon information to avoid trips to the database for common information required by an app to validate and display user info.
The UserId (or Int/Guid) value should always be set with a value to indicate that this object is not empty.
I use this class a lot to attach to serialize as a singl User Claim in User Claims, or Forms Authentication tickets
Westwind.AspNetCore.Security.UserState
Class Members
Member | Description | |
---|---|---|
![]() |
Constructor | |
![]() |
Clear | Initializes the data to empty defaults
public void Clear()
|
![]() ![]() |
CreateFromCookie | Retrieves userstate from a given cookie
public UserState CreateFromCookie(string cookieName, HttpContext context,
Type userStateType)
public TUserState CreateFromCookie
|
![]() ![]() |
CreateFromFormsAuthTicket | Creates a UserState object from authentication information in theForms Authentication ticket.IsEmpty() will return false if no data was loaded buta Userdata object is always returned
public UserState CreateFromFormsAuthTicket(HttpContext context)
|
![]() ![]() |
CreateFromString | Creates an instance of a userstate object from serializeddata.IsEmpty() will return true if data was not loaded. AUserData object is always returned.
public UserState CreateFromString(string userData)
public UserState CreateFromString(string userData, Type userStateType)
|
![]() ![]() |
CreateFromUserClaims | Creates a UserState object from authentication information in theForms Authentication ticket.IsEmpty() will return false if no data was loaded buta Userdata object is always returned
public T CreateFromUserClaims
public UserState CreateFromUserClaims(HttpContext context)
|
![]() |
FromString | Imports Id, Email and Name from a | separated string
public bool FromString(string itemString)
|
![]() |
IsAuthenticated |
public bool IsAuthenticated()
|
![]() |
IsEmpty | Determines whether UserState instanceholds user information - specificallywhether one of the UserID values is set.
public bool IsEmpty()
|
![]() |
ToString | Exports a short string list of Id, Email, Name separated by |
public string ToString()
|
![]() |
The user's email address or login acount | |
![]() |
IsAdmin | The users admin status - must be explicitly set.Also implicitly checks if the userstate recordto avoid scenarios where applications might notbe explicitly checking both for authentication and admin |
![]() |
Name | The display name for the userId |
![]() |
SecurityToken | A unique id created for this entry that can be used toidentify the user outside of the UserState context |
![]() |
UserId | The user's user Id as a string |
![]() |
UserIdGuid | Returns the User Id as a GUID if convertiable |
![]() |
UserIdInt | Returns the User Id as an int if convertiable |
Assembly: Westwind.AspNetCore.dll
© West Wind Technologies, 2025 • Updated: 2025-03-08
Comment or report problem with topic