Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何根据ASP.net中登录用户的角色禁用按钮_Asp.net - Fatal编程技术网

如何根据ASP.net中登录用户的角色禁用按钮

如何根据ASP.net中登录用户的角色禁用按钮,asp.net,Asp.net,在我的申请中,我有以下角色:, 用户、访问者和管理员。 在我的应用程序中,我想将删除按钮的访问权授予用户和管理员,而不是ASP.net中的用户。 如何实现此功能?您可以使用IsInRole if (User.IsInRole("Admin") || User.IsInRole("User")) { Button1.Enabled = true; } else { Button1.Enabled = false; } 如果我在同一个页面中有多个按钮(button2、button3

在我的申请中,我有以下角色:, 用户、访问者和管理员。 在我的应用程序中,我想将删除按钮的访问权授予用户和管理员,而不是ASP.net中的用户。
如何实现此功能?

您可以使用
IsInRole

if (User.IsInRole("Admin") || User.IsInRole("User"))
{
    Button1.Enabled = true;
}
else
{
    Button1.Enabled = false;
}

如果我在同一个页面中有多个按钮(button2、button3..等等),我可以做如下操作吗?如果(User.IsInRole(“Admin”)| | User.IsInRole(“User”){Button1.Enabled=true;button2.Enabled=true;}否则{Button1.Enabled=false;button2.Enabled=false;}我在.aspx页面中有代码,当我尝试代码时,如果(User.IsInRole(“Admin”)|| User.IsInRole(“User”)|| User.IsInRole(“Coord”){B_Back.Enabled=true;}否则{B_Back.Enabled=false;}它给了我以下错误,名称“B_Back”在当前上下文中不存在添加runat=server到butotnafth添加runat=server后,我得到以下错误“System.Web.UI.HtmlControls.HtmlInputButton”不包含“Enabled”的定义,并且没有扩展方法“Enabled”接受类型为“System.Web.UI.H”的第一个参数可以找到tmlControls.HtmlInputButton(是否缺少using指令或程序集引用?)