Specifies whether a member has any assigned role within a security context.
Parameter |
Type |
Description |
---|---|---|
member |
The member’s logon name. The property should be set to the logon name in the form: DOMAIN\USERNAME. |
|
context |
A security context object that specifies the application and scope properties of the request. |
Value |
Type |
Description |
---|---|---|
IsInApplicationRoleResult |
Specifies whether the member is in at least one role for the specified security context. True means the member has at least one role. False means the member has no assigned role. |
The following C# example determines whether a member has any assigned roles within a security context. The example’s security context uses the Microsoft Dynamics GP web service application. The member is identified by the logon name “DOMAIN\\username“. A message box displays whether or not a role exists.
using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using DynamicsSecurityServiceSample.DynamicsSecurityWebService; namespace DynamicsSecurityServiceSample { class Program { static void Main(string[] args) { ApplicationKey applicationKey; SecurityContext securityContext; bool roleExists; // Create an instance of the security service DynamicsSecurityService wsDynamicsSecurity = new DynamicsSecurityService(); // Use default credentials wsDynamicsSecurity.UseDefaultCredentials = true; // Create a security context object securityContext = new SecurityContext(); // Create the application key and add it to the security context object // Use the ID of the Dynamics GP web service application applicationKey = new ApplicationKey(); applicationKey.Id = "25cc1a21-2cc4-4b13-a1c8-eea186fb688a"; securityContext.ApplicationKey = applicationKey; // Determine whether a specified user has any role within a specified security context roleExists = wsDynamicsSecurity.IsInApplicationRole("DOMAIN\\username", securityContext); // Display a message indicating whether or not a role was found if (roleExists == true) { MessageBox.Show("A role was found"); } else { MessageBox.Show("A role could not be found"); } } } }