用于检测 SharePoint 用户是否具有特定权限级别的未弃用代码
在我们的应用程序中,我们有一些表单需要在当前用户具有特定权限级别时专门显示一些数据。这些用户属于 SPGroup,其中包括不应看到此数据的用户,因此在这种特殊情况下,我无法根据组成员身份进行过滤。
我当前的解决方案是使用 web.CurrentUser.Roles 并简单检查它是否包含正确名称的权限级别。 Roles 属于已弃用的 SPRole
类,因此尽管它在技术上可行,但我还是受到了警告消息的轰炸。它建议我使用 SPRoleAssignment
或 SPRoleDefinition
(该建议似乎是任意的,因为有些行推荐一种,而另一些行推荐另一种,即使它用于同一件事)。
但是,我似乎找不到任何方法可以直接从 SPUser
或 SPPrincipal
检索 SPRoleAssignment
或 SPRoleDefinition
对象对象,我也无法检索与 SPWeb
对象的当前用户具体对应的任何对象。
如何更新这些方法以使用未弃用的代码?我发现了确定用户权限的其他情况,但我还没有找到一种可以从当前网络或当前用户的起点开始工作的情况。这并不紧急,但它确实有助于避免为了找到更重要的警告而筛选所有这些警告。
In our application, we have some forms which need to show some data specifically if the current user has a specific permission level. These users belong to an SPGroup which includes users who should not see this data, so in this particular case I cannot filter based off of group membership.
My current solution has been to use web.CurrentUser.Roles
and use a simple check on whether it contains a permission level of the correct name. Roles is of the deprecated SPRole
class, so I am bombarded with warning messages despite the fact it technically works. It suggests that I use SPRoleAssignment
or SPRoleDefinition
(the recommendation seems arbitrary since some lines recommend one while others recommend the other even though it is being used for the same thing).
However, I cannot seem to find any method to directly retrieve an SPRoleAssignment
or SPRoleDefinition
object from an SPUser
or SPPrincipal
object, nor can I retrieve either object corresponding specifically to the current user of the SPWeb
object.
How can I update these methods to use non-deprecated code? I've found other cases of determining user permissions, but I haven't found one that will work from a starting point of the current web or the current user. It's not urgent, but it certainly is helpful to avoid having to sift through all of those warnings just to reach the more important warnings.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在实际对象上,例如 SPList,您可以调用
DoesUserHavePermission
方法,例如On the actual object, e.g. and SPList, you can call the
DoesUserHavePermission
method, e.g.