C# - Check whether user is an administrator

By , 12/5/2012
(0 ratings)
Checks if the logged in user is an administrator. This function can be easily modified for any other role.

Author: Jan Welker, translation by Michael List
/// <summary>
/// Checks, if the currently logged in user is an administrator
/// </summary>
/// <returns></returns>
bool IsAdministrator()
    WindowsIdentity myWindowsIdentity = WindowsIdentity.GetCurrent();
    WindowsPrincipal myWindowsPrincipal = new WindowsPrincipal(myWindowsIdentity);
    return myWindowsPrincipal.IsInRole(WindowsBuiltInRole.Administrator);



Log in, to comment!