gpt4 book ai didi

asp.net-mvc - MVC 3 - View 中的授权

转载 作者:行者123 更新时间:2023-12-04 06:16:13 24 4
gpt4 key购买 nike

在我看来,授权过滤器只能应用于 Controller 或操作级别。

是否可以在 View 中使用授权?比如说,在 ListView 的每一行中,管理员都有编辑、删除等按钮,而访客用户只能阅读。有可能实现吗?

谢谢。

最佳答案

使用条件语句,如

@if (HttpContext.Current.User.IsInRole("Admin"))

关于asp.net-mvc - MVC 3 - View 中的授权,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7207432/

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