根据当前用户角色动态隐藏Web部件 [英] Dynamically hiding web parts based on current user roles

查看:86
本文介绍了根据当前用户角色动态隐藏Web部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好
如何在asp.net中动态隐藏/显示网页部件。我使用这个来做同样的事情,但在本文中,他们在 AuthorizationFilter上有硬编码角色控件的属性,而不是我希望角色应该在运行时分配。我还尝试了另一种替代方法,我在.cs文件中声明变量''roles'',并在运行时将值分配给roles变量(并使用类似 AuthorizationFilter =<%#roles% > )但它对我不起作用,因为每次我获取 AuthorizationFilter 的值为空(如果我在标签上使用Text =<%#roles%>那么它显示其值但值不分配给 AuthorizationFilter )。我也试过



Hi How can I dynamically Hide/Show web-parts in asp.net. I am using this to doing same , but In this article they have hard coded roles on AuthorizationFilter attribute of control , instead I want roles should be assigned at runtime. I have also tried another alternate , I have declare variable ''roles'' in .cs file and at runtime assigning values to roles variable( and using like AuthorizationFilter=<% #roles %> ) but it doesnt work for me as each time I am getting value for AuthorizationFilter as blank(if I am using Text=<% #roles %> on label then it displays its value but value does not assign to AuthorizationFilter). I have also tried

if (User.IsInRole("Admin"))
   Label2.Visible = true;





但它仍会在Web部件区域内显示Web部件标题。



but it still display web part title inside web part zone.

推荐答案

我想你可以使用 LoginView [ ^ ] - 该页面底部有一个小例子。



最好的问候

Espen Harlinn
I guess you could use the LoginView[^] - there is a small example at the bottom of that page.

Best regards
Espen Harlinn


这篇关于根据当前用户角色动态隐藏Web部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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