Security and Authentication

Store Extra Information at Sign-In Time

Description
This example demonstrates store extra information at sign-in time.
Variables
Table Name
Select the table where user information is stored
UserId Field
Select the UserId field
Applies to
SignIn class
Code
 
/// 
/// Store information in session variable in loginSucceeded event.
/// This event is raised after user has successfully logged-in
/// Instead of creating a where string from database you might choose other
/// information to store (like time of sign in, for example).
/// 
protected void SignIn_LoginSucceeded(object sender, System.EventArgs e)
{
    // [BEGIN]: adding more info to session
    string userId = BaseClasses.Utils.SecurityControls.GetCurrentUserID();

    // Create where string 
    string whereStr = ${${Table Name}ClassName}.${UserId Field}.UniqueName + " = " + "'" + userId + "'";

    // Create the order by string
    BaseClasses.Data.OrderBy oB = null;
    
    // Get the record
    ${${Table Name}RecordClassName} myRecord  = ${${Table Name}ClassName}.GetRecord(whereStr, oB);

    // Set the extra information in the Session variable as shown below. 
    // Replace FirstName and LastName by you field names
    // where FirstName and LastName are the names of the cloumns that contiain the first name and the last name
    // string firstName = myRecord.FirstName;
    // string lastName = myRecord.LastName;
    // System.Web.HttpContext.Current.Session["firstName"] = firstName; 
    // System.Web.HttpContext.Current.Session["lastName"] = lastName; 
    // [END]: adding more info to session
}
     
Applies to
CSharpSignInPageClassConstructor class
Code
 
    // The following line will be inserted inside the
    // constructor for page class.
     this.LoginSucceeded += SignIn_LoginSucceeded; 
     

Terms of Service Privacy Statement