asp.net-core - 如何确保 HttpContext.Current 在 IdentityServer 通知期间不会丢失
问题描述
我有一个场景,我在设置代码中的客户端中使用通知事件非常简单,如下所示。这是一个使用 AspNetCore IdentityServer4 的 AspNet Mvc 4.72 客户端:
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
ClientId = "members",
...
Notifications = new OpenIdConnectAuthenticationNotifications
{
SecurityTokenValidated = notification =>
{
...
// Sometimes this is null but I have to make sure it is
// always available so I can initialize stuff here.
HttpContext.Current.<Use context here>;
return Task.CompletedTask;
}
}
});
实际上,更具体地说,我需要访问会话状态,但与其他一些直接相关的需求无关紧要。我不确定为什么会发生这种情况,但根据我的研究,它与 SynchronizationContext 和 AspNet Mvc 请求的生命周期有关。
如果有人对如何确保 HttpContext 的存在有明确的答案,请告诉我。
解决方案
推荐阅读
- amazon-dynamodb - 如何查询 AWS dynamodb 以获取每一小时、每一天和 30 天的数据?
- java - 我的 RecyclerViw 适配器出错,填充了 firebase 数据
- python - 如何执行存储在文件对象中的多个json对象
- linux - 为什么在这种情况下分配位置会导致无限循环?
- docker - 如何保存对 docker 容器和图像的更改
- java - 从发送到 AWS/Amazon SQS 的消息中删除无效字符
- bootstrap-4 - 关于 Accordion 的信息被推出,并且没有显示在 Bootstrap 上
- excel - 如果前面有一个字符串,你如何让一个单元格留空?
- python - 使用距离缺失值最近的日期填充缺失值
- c++ - 可以访问一个类中的播放器结构,但不能访问另一个类