Share via


BizPrivilege.RetrieveUserPrivileges Method

The RetrieveUserPrivileges method retrieves all the privileges a user has through his or her roles in the specified business unit.

Syntax

[Visual Basic .NET]
Public Function RetrieveUserPrivileges(
  ByVal Caller As CUserAuth,
  ByVal UserId As String
) As CRolePrivilege()
[C#]
public CRolePrivilege[] RetrieveUserPrivileges(
  CUserAuth  Caller,
  string  UserId
);
[C++]
public: CRolePrivilege* RetrieveUserPrivileges(
  CUserAuth*  Caller,
  String*  UserId
)  __gc[];

Parameters

Caller

Specifies the identity of the caller. See CUserAuth.

UserId

Specifies the ID of the user whose privileges you want to retrieve.

Return Value

Returns a CRolePrivilege[] type that specifies the privileges that the user holds. See CRolePrivilege.

Remarks

If there is an error, SOAP throws an exception and the error message is reported in System.Web.Services.Protocols.SoapException.Detail.OuterXml.

All IDs passed to the platform are GUIDs wrapped in braces. For example: {6522D89A-A752-4455-A2B0-51494C6957C3}

Example

[C#]
// strServer should be set with the name of the platform Web server
string strServer = "myservername";

// strVirtualDirectory should be set with the name of the Microsoft CRM
// virtual directory on the platform Web server
string strVirtualDirectory = "mscrmservices";

// Create the URL to the SRF files for platform objects
string strDir = "https://" + strServer + "/" + strVirtualDirectory + "/";

// BizUser proxy object
Microsoft.Crm.Platform.Proxy.BizUser oUser = new Microsoft.Crm.Platform.Proxy.BizUser ();
oUser.Credentials = System.Net.CredentialCache.DefaultCredentials;
oUser.Url = strDir + "BizUser.srf";

// SecRole proxy object
Microsoft.Crm.Platform.Proxy.BizPrivilege privilege   = new Microsoft.Crm.Platform.Proxy.BizPrivilege ();
privilege.Credentials = System.Net.CredentialCache.DefaultCredentials;
privilege.Url = strDir + "BizPrivilege.srf";

// Declare the caller
Microsoft.Crm.Platform.Proxy.CUserAuth userAuth = null;

string strErrorMsg = "";
Microsoft.Crm.Platform.Proxy.CRolePrivilege [] rolePrivResult = null;
try
{
   // Get the UserAuth of the current logged-on user
   userAuth = oUser.WhoAmI();

   // Retrieve all privileges of the caller user
   rolePrivResult = privilege.RetrieveUserPrivileges(userAuth, userAuth.UserId);
}
catch(System.Web.Services.Protocols.SoapException err)
{
   // Process the platform error here
   strErrorMsg = ("ErrorMessage: " + err.Message + " " + err.Detail.OuterXml + " Source: " + err.Source );
}
catch(Exception err)
{
   // Process other errors here
   strErrorMsg = ("ErrorMessage: " + err.Message + "Source: " + err.Source );

Requirements

Namespace: Microsoft.Crm.Platform.Proxy

Assembly: Microsoft.Crm.Platform.Proxy.dll

See Also

© 2005 Microsoft Corporation. All rights reserved.