Walkthrough: Determine Whether a User Is Authorized to Perform a Task

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

The latest Enterprise Library information can be found at the Enterprise Library site.

This walkthrough demonstrates how to use the Security Application Block to determine whether a user is authorized to perform a particular task.

To reproduce the demonstration

  1. Create a GenericPrincipal object representing the user and role information by adding the following code.

    IPrincipal principal = new GenericPrincipal(new GenericIdentity("tim"), new string[]{"Manager"});
    
    'Usage
    Dim principal As IPrincipal = New GenericPrincipal(New GenericIdentity("tim"), New String() {"Manager"})
    
  2. Perform the authorization check by adding the following code.

    bool authorized = ruleProvider.Authorize(principal, "Submit Order");
    
    'Usage
    Dim authorized As Boolean =ruleProvider.Authorize(principal, "Submit Order")