gpt4 book ai didi

authentication - asp.net mvc 3 : Page. User.IsInRole ("xy") 返回 null

转载 作者:行者123 更新时间:2023-12-04 03:13:22 25 4
gpt4 key购买 nike

我将一个 mvc 2 应用程序迁移到版本 3。

不幸的是,在我的部分登录文件中,当用户登录时抛出异常。Request.IsAuthenticated 返回 true,但 Page.User 返回 null!

而且当然
Page.User.IsInRole("xy")
抛出异常:
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:无法对空引用执行运行时绑定(bind)

如何使用 Razor 检查用户角色?

最佳答案

通过查看默认的 mvc3 项目找到了解决方案:

Context.User.IsInRole("xy")

而不是 Page.User.IsInRole("xy")

关于authentication - asp.net mvc 3 : Page. User.IsInRole ("xy") 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5314083/

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