• Decrease Text SizeIncrease Text Size

How do I execute my code after Authentication

Posted Date: 5/10/2023
    Printer Friendly Version   Email A Friend   Add This   Increase Text Size   Decrease Text Size
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 Code Samples Records
Related Taxonomy
  - How Do I?
  - Questions

Comments:

Be the first to leave a comment.
Please Login to post comments.