Export (0) Print
Expand All

Find All Privileges for a User

CRM 1.0

This sample finds all the privileges a user can access through their assigned roles.

Class Reference

Example

[C#]

public void GetUserPrivileges()
{
   // 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 = String.Concat("http://", strServer, "/",
                                 strVirtualDirectory, "/");

   // BizUser proxy object
   Microsoft.Crm.Platform.Proxy.BizUser bizUser 
               = new Microsoft.Crm.Platform.Proxy.BizUser ();
   bizUser.Credentials = System.Net.CredentialCache.DefaultCredentials;
   bizUser.Url = String.Concat(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 = String.Concat(strDir, "BizPrivilege.srf");

   String strErrorMsg;
   Microsoft.Crm.Platform.Proxy.CRolePrivilege [] rolePrivResult = null;
   try
   {
      // Get the UserAuth of the currently logged on user
      Microsoft.Crm.Platform.Proxy.CUserAuth userAuth = bizUser.WhoAmI();

      // Retrieve all privileges of the caller user from the business
      // to which he or she belongs
      rolePrivResult = privilege.RetrieveUserPrivileges(userAuth,
                                                        userAuth.UserId);
   }
   catch (System.Web.Services.Protocols.SoapException err)
   {
      // Process the platform error here
      strErrorMsg = String.Concat("ErrorMessage: ", err.Message, " ",
                      err.Detail.OuterXml, " Source: ", err.Source);
   }
}

© 2005 Microsoft Corporation. All rights reserved.


Show:
© 2014 Microsoft