Sometimes you need to execute your code after authentication.
We have a way to do this by executing OnAuthenticatiOnSuccessAndFailure. This method has access to the username of the person who was trying to log in, the UserId of that user successful (if authentication was successful)
You can copy the existing code and create OnAuthenticatiOnSuccessAndFailure.cs and move this file into Root/App_Code/Custom directory.
using System;
using System.Web;
namespace Centralpoint.WebSite.Modules
{
public partial class AuthenticationSources
{
partial void OnAuthenticatiOnSuccessAndFailure(string username, string password, ref DataInfo source, ref Guid userId, ref bool success)
{
HttpContext.Current.Trace.Warn("OnAuthenticatiOnSuccessAndFailure", $"username: {username} userId: {userId} success: {success}");
if(success)
{
HttpContext.Current.Trace.Warn("OnAuthenticatiOnSuccessAndFailure:success", $"{success}");
//Get User information
UserInfo userInfo = new UserInfo(userId);
//userInfo.Properties.Get("ContactFirstName");
//userInfo.Properties.Get("ContactLastName");
}
else
{
HttpContext.Current.Trace.Warn("OnAuthenticatiOnSuccessAndFailure:!success", $"{success}");
}
}
}
}
Keywords: Authentication, OnAuthenticatiOnSuccessAndFailure
Related CodeSamples Records