如果用户没有适当的权限,则让 Web 部件隐藏自身
如果用户在 SharePoint 中创建 Web 部件页面,然后向其中添加我的自定义 Web 部件之一,我想根据特定用户权限完全隐藏 Web 部件。
例如,我有一个报告 Web 部件,有些用户可以访问报告,有些则不能,我什至不希望某些用户知道报告存在。
我有一个自定义安全 API,用于确定是否允许或拒绝安全, 我想说:
protected override void OnInit(EventArgs e) {
bool allowed = PermissionServices.IsAllowed("Reports");
if (!allowed) {
this.Hide();
// Where 'this' is the web part
}
base.OnInit(e);
}
我不控制页面代码,因此它必须位于 Web 部分中。
If the user creates a web part page in SharePoint and then adds one of my custom web parts to it, I would like to completely hide a web part depending on a particular users permissions.
For example, I have a reporting web part some users have access to reports and some don't, I don't even want some users to know that reports exist.
I have a custom security API that use to determine if security is allowed or denied,
I would love to say:
protected override void OnInit(EventArgs e) {
bool allowed = PermissionServices.IsAllowed("Reports");
if (!allowed) {
this.Hide();
// Where 'this' is the web part
}
base.OnInit(e);
}
I don't control the page code so it has to be in the web part.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要查看 受众群体定位。
基本上,受众群体定位允许您根据查看该页面的人员组来自定义页面,以便经理可以转到“home.aspx”并查看包含一些统计信息的顶表结果 Web 部件,但如果常规开发人员登录到同一页面时,WebPart 将不会出现。
您应该小心混淆 受众和权限。 受众群体定位不会更改所涉及用户的权限。
编辑
感谢 Kirk 指出受众群体定位仅适用于 MOSS 而不适用于 WSS。
You are going to want to look into Audience Targeting.
Basically audience targeting allows you to customize a page based on the group of the person viewing it, so that a manager will go to "home.aspx" and see a top-sheet results WebPart that includes some statistics, but if a regular developer logs on to the same page, the WebPart won't appear.
You should be careful about confusing Audiences and Permissions. Audience targeting does NOT change the permissions of the users involved.
EDIT
Thanks to Kirk for pointing out that audience targeting only works in MOSS and not WSS.
您绝对可以在自定义 WebPart 的
Render()
方法中进行权限检查。 如果用户没有权限,则不渲染任何内容。You could definitely do your permissions check within your custom WebPart's
Render()
method. If the user doesn't have the permissions, just don't render anything.