0

When checking if a user is in a role, I typically use the following type of code. However, this code throws an exception if the user would be warned about a password that was to expire in the next 10 days (for example). Does anyone know a way to prevent this from happening?

using System.Security.Principal;
.
.
.
public UserDTO getCurrentUser()
{
    UserDTO U = new UserDTO();

    // Grab windows information
    WindowsIdentity CurrentUserIdentity = WindowsIdentity.GetCurrent();
    WindowsPrincipal CurrentUserPrincipal = new WindowsPrincipal(CurrentUserIdentity);
    U.isAuthorized = CurrentUserPrincipal.IsInRole("MYDOMAIN\\myrole");
    U.name = CurrentUserIdentity.Name;

    if (U.isAuthorized)
    {
        U.id = 1;
    }
    else // the user isn't authorized
    {
        U.id = 0;
    }
    return U; 
} // get current user

I'm using the .NET framework 4.5 for this code.

Thanks! Ray

rlillbac
  • 71
  • 8
  • What's the exact exception? –  Aug 23 '16 at 19:35
  • Where does the error occur, and what exception type is it? You can catch just that exception type and then decide if you want to let the user know they need to update their password. – Broom Aug 23 '16 at 19:46
  • Agree with broom find out why exactly it if failing in try catch and decide what to do, also you might want to check once http://stackoverflow.com/questions/1394025/active-directory-ldap-check-account-locked-out-password-expired – Vinay Pandey Aug 23 '16 at 20:23

0 Answers0