英文:
How do I get hold of the current ClaimsPrincipal who's being SignedOut?
问题
在我的自定义 CookieAuthenticationEvents 类型中,我已经重写了SigningOut,如下所示,但无法弄清如何获取正在注销的Principal。我试图这样做是为了记录谁/何时登录和注销应用程序。
public override Task SigningOut(CookieSigningOutContext context)
{
// 如何获取ClaimsPrincipal?
return base.SigningOut(context);
}
然而,SigningOut重写提供了一个类似这样的Principal属性:
public override Task SigningIn(CookieSigningInContext context)
{
_logger.LogInformation($"Signing In SessionID: {context.Principal?.GetClientSessionId()}");
return base.SigningIn(context);
}
英文:
In my custom CookieAuthenticationEvents type I have overriden SigningOut like this, but cannot figure out how to get hold of the Principal who's being signed out. I am trying to do this so I can log who/when is being logged in and out of the app.
public override Task SigningOut(CookieSigningOutContext context)
{
// How to get hold of the ClaimsPrincipal?
return base.SigningOut(context);
}
The SigningOut override however does provide a Principal property like this:
public override Task SigningIn(CookieSigningInContext context)
{
_logger.LogInformation($"Signing In SessionID: {context.Principal?.GetClientSessionId()}");
return base.SigningIn(context);
}
答案1
得分: 1
你可以使用 context.HttpContext.User
public override Task SigningOut(CookieSigningOutContext context)
{
var user = context.HttpContext.User;
// 记录用户信息
return base.SigningOut(context);
}
英文:
You can use context.HttpContext.User
public override Task SigningOut(CookieSigningOutContext context)
{
var user = context.HttpContext.User;
// log the user
return base.SigningOut(context);
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论