Solved

C sharp user interface security/permissions

Posted on 2009-05-10
2
415 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
Comment Utility
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
Comment Utility
that might work, but I'm trying to avoid using Role Based Secuirty.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now