Compartilhar via


SPWeb.DoesUserHavePermissions method (String, SPBasePermissions)

Indica se o usuário especificado tem um conjunto de permissões especificado.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

'Declaração
Public Function DoesUserHavePermissions ( _
    login As String, _
    permissionMask As SPBasePermissions _
) As Boolean
'Uso
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
)

Parâmetros

  • login
    Type: System.String

    O nome do usuário (Domain\User_Alias).

Valor retornado

Type: System.Boolean
true se o usuário possui as permissões especificadas; Caso contrário, false.

Comentários

Este método testa se as permissões no permissionMask correspondem àquelas retornado por GetUserEffectivePermissions(String).

O usuário atual deve ter direitos de EnumeratePermissions para verificar as permissões de outros usuários.

Examples

O exemplo a seguir é um aplicativo de console que imprime uma lista de usuários que receberam explicitamente permissão para gerenciar a lista no site atual.

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();
        }
    }
}

Ver também

Referência

SPWeb class

SPWeb members

DoesUserHavePermissions overload

Microsoft.SharePoint namespace

EnsureUser(String)