gpt4 book ai didi

c# - 在 HttpContext.Current.User (IPrinciple) 中存储扩展的 IIdentity

转载 作者:行者123 更新时间:2023-11-30 22:46:03 25 4
gpt4 key购买 nike

我创建了一个 ExtendedId 类,它扩展了 GenericIdentity。 (这存储 ID 和名称)

在 httpmodule 中,我将这个扩展 ID 存储在 Current.User 中,如下所示:

HttpContext.Current.User = new GenericPrincipal(myExtendedId, roles);

问题是,稍后我如何再次获取我的 ExtendedId 类型?

如果我尝试这样做:

ExtendedId eId = (ExtendedId)HttpContext.Current.User.Identity;

我得到一个转换错误。我有一种感觉,我在这里用类型转换做了一些愚蠢的事情,但今天早上我有点模糊。

最佳答案

尝试

ExtendedId eId = (ExtendedId )((GenericPrincipal)HttpContext.Current.User).Identity;

ExtendedId eId = ((GenericPrincipal)HttpContext.Current.User).Identity as ExtendedId;

关于c# - 在 HttpContext.Current.User (IPrinciple) 中存储扩展的 IIdentity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2832681/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com