Activities of "Priyanka"

hi

var userPrincipal = await SignInManager.CreateUserPrincipalAsync(user); 
using (CurrentPrincipalAccessor.Change(userPrincipal)) 
{ 
       await IdentitySecurityLogManager.SaveAsync() 
} 

SaveAsysc required to pass IdentitySecurityLogContext and in IdentitySecurityLogContext object only I'm not getting userId property, how userPrincipal is useful here ?

Hi

Add your code into CurrentPrincipalAccessor' changescope.

var userPrincipal = await SignInManager.CreateUserPrincipalAsync(user);  
using (CurrentPrincipalAccessor.Change(userPrincipal))  
{  
      await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext() 
      { 
          Identity = IdentitySecurityLogIdentityConsts.IdentityExternal, 
          Action = "Login" + result 
      }); 
}  
var userPrincipal = await SignInManager.CreateUserPrincipalAsync(user);  
using (CurrentPrincipalAccessor.Change(userPrincipal))  
{  
       await IdentitySecurityLogManager.SaveAsync(new IdentitySecurityLogContext() 
      { 
              Identity = IdentitySecurityLogIdentityConsts.IdentityExternal, 
              Action = result.ToIdentitySecurityLogAction(), 
              UserName = user.Name 
      }); 
}  

thanks, it is working, but how can we do the same in logout as on logout userId is updated but username is null.

hi

Please share the code of yourlogout code, Thanks

we are calling this method, first we are calling external logout URL.

[Dependency(ReplaceServices = true)]
[ExposeServices(typeof(LoggedOutModel))]
public class CustomLogout: LoggedOutModel
{
   
    public override Task<IActionResult> OnGetAsync()
    {
        IConfigurationRoot _config = new ConfigurationBuilder().SetBasePath(Directory.GetParent(AppContext.BaseDirectory).FullName)
             .AddJsonFile("appsettings.json", false).Build();
        var externalLogout = _config.GetSection("ADFSConfig:EndSession").Get<string>();
        Response.Redirect(externalLogout);
        return base.OnGetAsync();
    }
     
}

hi

We have output the log on LogoutModel. Why you are overriding the LoggedOutModel?

I'm overriding as before logout, I need to call ADFS logout as well so first I'm redirecting to logout from third party than calling ABP's logout. With ABP's method, I am able to save the userid and action in my log table but username is not updating.

Hi,

Could you explain it in detail? thanks

using this code, it is not redirecting to login page, I want if new session is active in new browser, then the previous browser's application should redirect to login page.

if (httpContext.User.Identity != null && httpContext.User.Identity.AuthenticationType == "Identity.Application")
                    {
                        await httpContext.RequestServices.GetRequiredService<AbpSignInManager>().SignOutAsync();
                        await httpContext.ChallengeAsync("Identity.Application");
                    }

                    //JWT
                    if (httpContext.User.Identity != null && httpContext.User.Identity.AuthenticationType == "AuthenticationTypes.Federation")
                    {
                        await httpContext.ChallengeAsync(JwtBearerDefaults.AuthenticationScheme);
                    }

hi

You can't get user info in the LoggedOutModel class. so you can't output a username to security logs.

so, can we say that it's not possible to update username in log table for logout action?

Yes, you can do that in the LoggedOutModel class

If we can, then could you please help how can we?

sorry, you can't do that in the LoggedOutModel class

Ok, thanks for your support.

Hi,

So, preventing concurrent logins from different browsers is working now but the previous browser did not redirect to the login page

You can redirect:

if (httpContext.User.Identity != null && httpContext.User.Identity.AuthenticationType == "Identity.Application") 
{ 
    await httpContext.RequestServices.GetRequiredService<AbpSignInManager>().SignOutAsync(); 
    //await httpContext.ChallengeAsync("Identity.Application"); 
     
    var redirectUrl = "..."; 
    httpContext.Response.Redirect(redirectUrl); 
    return; 
} 

I tried this but it is stuck in infinite loop, it is redirecting to login and somehow it is coming again on this condition, condition is satisfied and redirecting again and this whole process is keep going.

What is the difference if we call below mention functions: await httpContext.RequestServices.GetRequiredService<AbpSignInManager>().SignOutAsync(); await httpContext.RequestServices.GetRequiredService<LoggedOutModel>().OnGetAsync();

ABP Framework version: v5.3.2

UI Type:React

Database System: EF Core (SQL Server)

Tiered (for MVC) or Auth Server Separated (for Angular): yes

Exception message and full stack trace:NA

Steps to reproduce the issue: Login and Logout

Showing 11 to 20 of 133 entries
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.2.0-preview. Updated on January 20, 2026, 07:04
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.