如何基于用户角色来启用和禁用按钮? [英] how to enable and disable button based on user role?

查看:178
本文介绍了如何基于用户角色来启用和禁用按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为成员,并在Asp.Net另一个网站管理员。

I have a role called 'member' and another 'admin' in Asp.Net website.

我以前那样,那按钮应可见或不可见,我成功了,但是,我不能够得到正确的code(aspx.cs)禁用按钮,它可能是查看但不能在所有可访问的。

I did before, that button should be visible or not and i am successful in that,but,i am not able to get the proper code(aspx.cs) to disable the button so that it may be in view but not at all accessible.

<asp:Button ID="Button4" runat="server" PostBackUrl="~/report.aspx" 
   Text="print in report format" Width="173px" 
   Enabled='<%# HttpContext.Current.User.IsInRole("Admin") %>' /> 

我想,只要一个会员注册按钮,然后报告应该对他关闭。

i want that whenever a member login then button "report" should be disabled for him.

推荐答案

您必须将 Button.Enabled 属性值设置为根据 HttpContext.Current.User.IsInRole(管理员)函数的返回值。

You have to set the Button.Enabled property value to according to the HttpContext.Current.User.IsInRole("admin") function returned value.

无论是在HTML:

<Button ... Enabled='<%# HttpContext.Current.User.IsInRole("Admin") %>' ... >

或在code背后:

Button.Enabled = HttpContext.Current.User.IsInRole("Admin");

这篇关于如何基于用户角色来启用和禁用按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆