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