阻止用户激活 Sharepoint 中的功能
如果我在场级别部署解决方案,是否可以通过某种方式阻止各个网站集的所有者激活该解决方案中存在的功能?
If I deploy a solution at farm level, is there a way by which i can prevent the owners of the various site collections from activating the features present in that solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
阻止网站集用户激活特定功能的一个简单方法是将其标记为隐藏。这些功能实际上只允许场管理员通过 STSADM 命令激活。
要隐藏功能,请将功能元素的隐藏属性更新为“TRUE”,如下所示:
或者,如果您使用的是 SharePoint 2010,则可以使用功能包通过将一组功能定位到一组特定用户来解决此问题。
A simple way to prevent site collection users from activating a certain feature is to mark it as hidden. These features are then effectively only allowed to be activated by farm administrators through STSADM commands.
To hide a feature update the Hidden attribute of the Feature element to ‘TRUE’ as shown below:
Alternatively if you are using SharePoint 2010 you can use Feature Packs to solve this problem by targeting a set of features to a particular set of users.
查看 Zevenseas 功能拦截器。
Have a look at the Zevenseas feature blocker.
如果在功能激活期间发生错误,则不会激活该功能,并且会撤回可能已作为 Elements Manifest 的一部分部署的任何效果。
因此,通过巧妙地使用此功能,您可以使用功能接收器的 FeatureActivated 部分来检查谁正在激活它,并抛出 UnauthorizedAccessException 和一条适当的错误消息,详细说明为什么无法激活该功能。这将显示为标准 SharePoint 错误页面,并包含您指定的消息。如果您已经在该功能上有一个功能接收器,则需要将其附加到 FeatureActivated 部分的开头,以便不会发生任何编程操作(与元素清单不同,这些操作不会在激活不成功时撤回)。
如果您以前没有使用过功能接收器,则只需两部分即可建立它。
在要素的要素 XML 中,将以下两个属性添加到要素节点。
编写一个接收器类。它继承自
SPFeatureReceiver
,并且在FeatureActivated
、FeatureDeactivating
、FeatureInstalled
和FeatureUninstalling 中具有 4 个必需的重写
。对于最后 3 个过程,您无需执行任何操作。您将在FeatureActivated
方法中编写安全检查。If an error occurs during feature activation, it will not activate the feature and will retract any effects which might have been deployed as part of the Elements Manifest.
So, through crafty usage of this, you can use the FeatureActivated portion of a feature receiver to check who is activating it, and throw an UnauthorizedAccessException with an appropriate error message detailing why the feature cannot be activated. This will show up as the standard SharePoint error page with the message you specify. If you already have a feature receiver on the feature, you need to append this at the start of the FeatureActivated portion, so that any programmatic actions don't occur (unlike elements manifest, these are not retracted on unsuccessful activation).
If you haven't used a Feature Receiver before, you just need two parts to establish it.
In the feature XML of your feature, add the following two attributes to the Feature node.
Write a receiver class. This inherits from
SPFeatureReceiver
, and has 4 required overrides inFeatureActivated
,FeatureDeactivating
,FeatureInstalled
, andFeatureUninstalling
. You don't have to do anything for the last 3. You'll write your security check in theFeatureActivated
method.