如果我在场级别部署解决方案,是否有办法阻止各种网站集的所有者激活该解决方案中存在的功能?
3 回答
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:
<Feature
Id="AD2146D-62DA-4911-DBC1-AE177DE40084"
Title="Restricted Web Parts"
Hidden="TRUE"
.../>
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.
如果在功能激活期间发生错误,它将不会激活该功能,并将收回任何可能已作为元素清单的一部分部署的效果。
因此,通过巧妙地使用它,您可以使用功能接收器的 FeatureActivated 部分来检查谁在激活它,并抛出 UnauthorizedAccessException 并带有适当的错误消息,详细说明无法激活该功能的原因。这将显示为带有您指定消息的标准 SharePoint 错误页面。如果您已经在该功能上拥有一个功能接收器,则需要在 FeatureActivated 部分的开头附加它,以便不会发生任何编程操作(与元素清单不同,这些不会在激活失败时收回)。
如果您之前没有使用过 Feature Receiver,您只需要两个部分来建立它。
在要素的要素 XML 中,将以下两个属性添加到要素节点。
ReceiverAssembly=(four-part-assembly-string) ReceiverClass=(full namespace.class name of receiver class)
编写一个接收器类。这继承自,并且在、、和
SPFeatureReceiver
中具有 4 个必需的覆盖。对于最后 3 个,您无需执行任何操作。您将在方法中编写安全检查。FeatureActivated
FeatureDeactivating
FeatureInstalled
FeatureUninstalling
FeatureActivated