dc

dc

  • NA
  • 663
  • 0

C# desktop access active directory groups

Jun 30 2013 10:30 AM
I have a C# 2010 desktop application where I have code setup to see if a user is a member of an active directory group. I am using WindowsIdentity to check the current users active directory group level. The following code is not working. Thus can you tell me how to what is wrong with the code below?

If you think the code listed below will not work, can you tell me how you would modify the code listed below?

If you do no see anything wrong, can you tell me what to suggest to the network people at my company to suggest to them what is wrong?

using ActiveDirectoryCommon;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Collections.Specialized;
using System.Deployment.Application;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.Remoting;
using System.IO;
using System.Web;
using System.Configuration; // required to obtain the values from the
ConfigurationManager.Appsettings in the app.config file
using System.Security.Principal;
using System.Threading;


namespace File_Reject
{
    static class Program
    {
        /// <summary>
        internal static ActiveDirectoryUser CurUser;
        [STAThread]
     

        static void Main()
          {
              try
              {
              Application.EnableVisualStyles();
             Application.SetCompatibleTextRenderingDefault(false);
             CurUser = new ActiveDirectoryUser();
             if
(!Thread.CurrentPrincipal.IsInRole(Environment.UserDomainName + "\\" + ConfigurationManager.AppSettings["role_File_Upload"]))
              {
                MessageBox.Show("You do not have authortity to access File Transfer. Please contact your network administrator if you have any
questions.", "File Transfer Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                      return;
                  }
                  Application.Run(new FileReject());
              }
                catch (Exception e)
              {
                  //console.write(e.Message);
                
              }

        }
    }
}
----------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Reflection;
using System.IO;
using System.Threading;
using System.Web;
using System.Windows.Forms;
using System.Security.Principal;


namespace ActiveDirectoryCommon
{
    public class ActiveDirectoryUser
    {
        public ActiveDirectoryUser()
        {
           
AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
            Thread.CurrentPrincipal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
        }
    }
}
-----------
<?xml version="1.0"?>
<configuration>

  <appSettings>
    <add key="role_File_Upload" value="File_Upload" />
  </appSettings>

</configuration>
------------


Answers (1)