SPWeb.DoesUserHavePermissions method (String, SPBasePermissions)
指示指定的使用者是否有指定的使用權限集合。
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
Public Function DoesUserHavePermissions ( _
login As String, _
permissionMask As SPBasePermissions _
) As Boolean
'用途
Dim instance As SPWeb
Dim login As String
Dim permissionMask As SPBasePermissions
Dim returnValue As Boolean
returnValue = instance.DoesUserHavePermissions(login, _
permissionMask)
public bool DoesUserHavePermissions(
string login,
SPBasePermissions permissionMask
)
參數
login
Type: System.String使用者名稱 (Domain\User_Alias) 中。
permissionMask
Type: Microsoft.SharePoint.SPBasePermissions列舉值的位元組合,指定一組權限。
傳回值
Type: System.Boolean
true如果使用者有指定的使用權限 ;否則, false。
備註
這個方法會測試是否在permissionMask中的使用權限符合傳回的GetUserEffectivePermissions(String)。
目前的使用者必須具有EnumeratePermissions權限,來檢查其他使用者的權限。
Examples
下列範例是一個主控台應用程式,列印一份已明確地指派管理目前網站上的清單的權限的使用者。
Imports System
Imports Microsoft.SharePoint
Module Test
Sub Main()
Using site As SPSite = New SPSite("https://localhost")
Using web As SPWeb = site.OpenWeb()
' Make sure the current user can enumerate permissions.
If web.DoesUserHavePermissions(SPBasePermissions.EnumeratePermissions) Then
' Specify the permission to check.
Dim permissionToCheck As SPBasePermissions = SPBasePermissions.ManageLists
Console.WriteLine("The following users have {0} permission:", permissionToCheck)
' Check the permissions of users who are explicitly assigned permissions.
Dim users As SPUserCollection = web.Users
Dim user As SPUser
For Each user In users
Dim login As String = user.LoginName
If web.DoesUserHavePermissions(login, permissionToCheck) Then
Console.WriteLine(login)
End If
Next
End If
End Using
End Using
Console.ReadLine()
End Sub
End Module
using System;
using Microsoft.SharePoint;
namespace Test
{
class Program
{
static void Main(string[] args)
{
using (SPSite site = new SPSite("https://localhost"))
{
using (SPWeb web = site.OpenWeb())
{
// Make sure the current user can enumerate permissions.
if (web.DoesUserHavePermissions(SPBasePermissions.EnumeratePermissions))
{
// Specify the permission to check.
SPBasePermissions permissionToCheck = SPBasePermissions.ManageLists;
Console.WriteLine("The following users have {0} permission:", permissionToCheck);
// Check the permissions of users who are explicitly assigned permissions.
SPUserCollection users = web.Users;
foreach (SPUser user in users)
{
string login = user.LoginName;
if (web.DoesUserHavePermissions(login, permissionToCheck))
{
Console.WriteLine(login);
}
}
}
}
}
Console.ReadLine();
}
}
}
請參閱
參照
DoesUserHavePermissions overload