Solved

C sharp user interface security/permissions

Posted on 2009-05-10
2
417 Views
Last Modified: 2013-12-17
I've searched the web for the last 2 days and cannot find what any help, so here I am.

I'm looking for c sharp samples on implementing a user interface security system. Not RBS. I need to be able to assign access permissions to add, edit or delete buttons on a form based on user or group level security.
0
Comment
Question by:gnixon14
2 Comments
 
LVL 3

Accepted Solution

by:
nhenny2009 earned 500 total points
ID: 24350220
If I am understanding your question correctly, then try the code below to help you determine the users "group" membership then you can enable/disable buttons as needed based on their group membership.  Take a close look at "WindowsBuiltInRole"...this is what will allow you to do other checks besides "admin" as I have in the example below.

Hope this helps.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Security.Principal;
 
 
namespace testingapp
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            bool IsAdmin = false;
            AdminCheck AC = new AdminCheck();
            IsAdmin = AC.IsUserAdministrator();
            MessageBox.Show("Is user \"" + System.Environment.UserName + "\" is an Admin? " + IsAdmin.ToString(), "Admin Check"); 
            
        }
    }
 
    public class AdminCheck
    {
 
        /// <summary>
        /// method for checking to see if the logged in user
        /// is in the Administrator's group
        /// </summary>
        /// <returns></returns>
        public bool IsUserAdministrator()
        {
            //bool value to hold our return value
            bool isAdmin;
            try
            {
                //get the currently logged in user
                WindowsIdentity user = WindowsIdentity.GetCurrent();
                WindowsPrincipal principal = new WindowsPrincipal(user);
                isAdmin = principal.IsInRole(WindowsBuiltInRole.Administrator);
            }
            catch (UnauthorizedAccessException ex)
            {
                isAdmin = false;
                MessageBox.Show(ex.Message);
            }
            catch (Exception ex)
            {
                isAdmin = false;
                MessageBox.Show(ex.Message);
            }
            return isAdmin;
        }
 
    }
}

Open in new window

0
 

Author Comment

by:gnixon14
ID: 24370433
that might work, but I'm trying to avoid using Role Based Secuirty.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question