Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

C sharp user interface security/permissions

Posted on 2009-05-10
2
Medium Priority
?
422 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 3

Accepted Solution

by:
nhenny2009 earned 1500 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

705 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