Click here to Skip to main content
15,917,702 members
Home / Discussions / C#
   

C#

 
AnswerRe: c# generate a ctrl from an xml or from a DB Pin
jschell30-Aug-11 8:35
jschell30-Aug-11 8:35 
QuestionC#.net stop program early Pin
dcof29-Aug-11 11:57
dcof29-Aug-11 11:57 
AnswerRe: C#.net stop program early Pin
Luc Pattyn29-Aug-11 12:06
sitebuilderLuc Pattyn29-Aug-11 12:06 
AnswerRe: C#.net stop program early Pin
PIEBALDconsult29-Aug-11 14:58
mvePIEBALDconsult29-Aug-11 14:58 
AnswerRe: C#.net stop program early Pin
Dylan Morley30-Aug-11 1:47
Dylan Morley30-Aug-11 1:47 
GeneralRe: C#.net stop program early Pin
dcof30-Aug-11 3:53
dcof30-Aug-11 3:53 
GeneralRe: C#.net stop program early [modified] Pin
Dylan Morley30-Aug-11 3:59
Dylan Morley30-Aug-11 3:59 
QuestionC#.net active directory options Pin
dcof29-Aug-11 7:33
dcof29-Aug-11 7:33 
I have the following questions to ask about a C#.net 2008 desktop application that i want to modify by accessing the active directory values:

1. I am assuming the following code accesses the active directory and only keeps one active directory group value at a time. if not, can you tell me what is wrong with my assupmption.

a. The following code is the start call:

void InitBrowser()
{
CurrentUser = new TUser();
UserIs_Read = CurrentUser.HasTRole(TUser.TRole.Reader);

}

b. The following is the code it calls;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Security.Principal;

namespace T.Common
{
public class TUser
{
public enum TRole
{
User = 0,
Manager = 1,
Administrator = 2,
Reader =3
}

public WindowsIdentity Identity;
public WindowsPrincipal Principal;

string _Domain;
public string Domain
{
get { return _Domain; }
}

string _Username;
public string Username
{
get { return _Username; }
}

public TUser()
{
this.Identity = WindowsIdentity.GetCurrent();
string[] NameInfo = this.Identity.Name.Split('\\');
_Domain = NameInfo[0];
_Username = NameInfo[1];
}

public bool HasTUser(TRole Role)
{
switch (Role)
{
case TRole.Reader:
return IsInGroup("Reader");
case Reader.Manager:
return IsInGroup("Managers");
//break;
case EnrollTracRole.Administrator:
return IsInGroup("Administrators");
//break;
case EnrollTracRole.User:
return true;
//break;
default:
return false;
}
}

public bool IsInGroup(string GroupName)
{


if (this.Principal == null)
{
this.Principal = new WindowsPrincipal(this.Identity);
}

return this.Principal.IsInRole(GroupName);
}


2. Would I somehow benefit from the code below instead of using the code I listed above? (the code below is just a small part of the active directory logic I would be using) If so, can you tell me how the following code is better:



private String[] ADSearch(String ConnectionString, String filter, String field){

DirectoryEntry SearchRoot =

new DirectoryEntry(ConnectionString, _userName, _pwd);

DirectorySearcher searcher =

new DirectorySearcher (SearchRoot, filter);

{

SearchRoot,

Filter = filter,

PageSize = 100

};

seararcher.PropertiesToLoad.Clear();

searcher.PropertiesToLoad.Add(field);

try


{


using (SearchResultCollection results = searcher.FindAll())


{


List<string> r = new List<string>();

foreach (SearchResult searchResult in results)



{

var prop = searchResult.Properties[field];
for (int index = 0; index < prop.Count; index++)
r.Add(prop[index].ToString());
}
return r.Count > 0 ? r.ToArray() : new string[0];


}


}


catch (Exception ex)


{

throw new ProviderException("Unable to query Active Directory.", ex);


}


}

public bool ValidateUser(string username, string password)


{


bool result = false;


try

{


using (var context =

new PrincipalContext(ContextType.Machine,_domain, null, _userName, _pwd))

{

result = context.ValidateCredentials(username, password);

}

}

catch (Exception ex)

{

/ TODO: log exception

}

return result;


}
AnswerRe: C#.net active directory options Pin
Richard Andrew x6429-Aug-11 11:22
professionalRichard Andrew x6429-Aug-11 11:22 
GeneralRe: C#.net active directory options Pin
dcof29-Aug-11 16:57
dcof29-Aug-11 16:57 
GeneralRe: C#.net active directory options Pin
Richard Andrew x6429-Aug-11 17:00
professionalRichard Andrew x6429-Aug-11 17:00 
QuestionC# low level mouse hook and form events Pin
Ak47AL29-Aug-11 6:21
Ak47AL29-Aug-11 6:21 
AnswerRe: C# low level mouse hook and form events Pin
BillWoodruff29-Aug-11 18:13
professionalBillWoodruff29-Aug-11 18:13 
GeneralRe: C# low level mouse hook and form events Pin
Ak47AL31-Aug-11 5:47
Ak47AL31-Aug-11 5:47 
GeneralRe: C# low level mouse hook and form events Pin
BillWoodruff31-Aug-11 19:11
professionalBillWoodruff31-Aug-11 19:11 
QuestionRegistry Permissions Pin
Zach.Saunders29-Aug-11 4:50
Zach.Saunders29-Aug-11 4:50 
AnswerRe: Registry Permissions Pin
#realJSOP29-Aug-11 5:28
professional#realJSOP29-Aug-11 5:28 
GeneralRe: Registry Permissions [modified] Pin
Zach.Saunders29-Aug-11 6:18
Zach.Saunders29-Aug-11 6:18 
GeneralRe: Registry Permissions Pin
Anthony Mushrow29-Aug-11 7:36
professionalAnthony Mushrow29-Aug-11 7:36 
AnswerRe: Registry Permissions Pin
Abhinav S29-Aug-11 6:51
Abhinav S29-Aug-11 6:51 
AnswerRe: Registry Permissions Pin
Zach.Saunders29-Aug-11 8:34
Zach.Saunders29-Aug-11 8:34 
GeneralRe: Registry Permissions Pin
Anthony Mushrow29-Aug-11 8:48
professionalAnthony Mushrow29-Aug-11 8:48 
GeneralRe: Registry Permissions Pin
Zach.Saunders29-Aug-11 9:04
Zach.Saunders29-Aug-11 9:04 
GeneralRe: Registry Permissions Pin
Anthony Mushrow29-Aug-11 9:24
professionalAnthony Mushrow29-Aug-11 9:24 
GeneralRe: Registry Permissions Pin
Zach.Saunders29-Aug-11 10:47
Zach.Saunders29-Aug-11 10:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.