Click here to Skip to main content
15,902,636 members
Home / Discussions / C#
   

C#

 
GeneralRe: Problem while reading data from excel in c# Pin
Wayne Gaylard30-Aug-11 23:06
professionalWayne Gaylard30-Aug-11 23:06 
QuestionGet object back from server with .net remoting and Socket connection Pin
MahieuBrecht30-Aug-11 20:03
MahieuBrecht30-Aug-11 20:03 
AnswerRe: Get object back from server with .net remoting and Socket connection Pin
Michael J. Eber8-Sep-11 8:10
Michael J. Eber8-Sep-11 8:10 
Questioncompare two active directory methods Pin
dcof30-Aug-11 11:50
dcof30-Aug-11 11:50 
Questionswitch statement Pin
dcof30-Aug-11 8:31
dcof30-Aug-11 8:31 
AnswerRe: switch statement Pin
PIEBALDconsult30-Aug-11 8:48
mvePIEBALDconsult30-Aug-11 8:48 
AnswerRe: switch statement PinPopular
OriginalGriff30-Aug-11 9:48
mveOriginalGriff30-Aug-11 9:48 
AnswerRe: switch statement Pin
Dylan Morley1-Sep-11 1:25
Dylan Morley1-Sep-11 1:25 
I showed you how determine group membership in this post[^]

You need to use the IsInRole method of the CurrentPrincipal object to check for membership, which you could do in a simple if statement.

C#
if (Thread.CurrentPrincipal.IsInRole(@"MYDOMAIN\MyApplicationAdministrators")
{
    // User is an administrator, apply admin rights - whatever they may be
}
else if (Thread.CurrentPrincipal.IsInRole(@"MYDOMAIN\MyApplicationMangers")
{
     // User is a manager, apply manager rights - whatever they may be
}


You wouldn't really use a switch statement for this. Also, you can use imperative or declarative security to check for group membership at method level as well, e.g.

http://msdn.microsoft.com/en-us/library/system.security.permissions.principalpermissionattribute.aspx[^]

C#
// Only members of Admin role can call this method
[PrincipalPermission(SecurityAction.Demand, Role = "MYDOMAIN\MyApplicationAdministrators")]
static void CheckAdministrator()
{
    Console.WriteLine("User is an administrator");
}

QuestionC# and USB IR camera Pin
sandy630-Aug-11 2:39
sandy630-Aug-11 2:39 
AnswerRe: C# and USB IR camera Pin
BobJanova30-Aug-11 4:48
BobJanova30-Aug-11 4:48 
SuggestionRe: C# and USB IR camera Pin
DaveAuld30-Aug-11 6:34
professionalDaveAuld30-Aug-11 6:34 
QuestionPer Pixel Access in C# winforms Pin
Thomas.D Williams30-Aug-11 2:17
Thomas.D Williams30-Aug-11 2:17 
AnswerRe: Per Pixel Access in C# winforms Pin
lukeer30-Aug-11 4:28
lukeer30-Aug-11 4:28 
GeneralRe: Per Pixel Access in C# winforms Pin
Thomas.D Williams30-Aug-11 5:26
Thomas.D Williams30-Aug-11 5:26 
GeneralRe: Per Pixel Access in C# winforms Pin
BobJanova30-Aug-11 7:04
BobJanova30-Aug-11 7:04 
GeneralRe: Per Pixel Access in C# winforms Pin
Thomas.D Williams30-Aug-11 7:13
Thomas.D Williams30-Aug-11 7:13 
GeneralRe: Per Pixel Access in C# winforms Pin
Pete O'Hanlon30-Aug-11 7:20
mvePete O'Hanlon30-Aug-11 7:20 
GeneralRe: Per Pixel Access in C# winforms Pin
Thomas.D Williams30-Aug-11 11:17
Thomas.D Williams30-Aug-11 11:17 
GeneralRe: Per Pixel Access in C# winforms Pin
BobJanova30-Aug-11 7:38
BobJanova30-Aug-11 7:38 
GeneralRe: Per Pixel Access in C# winforms Pin
Thomas.D Williams30-Aug-11 11:12
Thomas.D Williams30-Aug-11 11:12 
GeneralRe: Per Pixel Access in C# winforms Pin
BobJanova30-Aug-11 23:02
BobJanova30-Aug-11 23:02 
GeneralRe: Per Pixel Access in C# winforms Pin
Thomas.D Williams30-Aug-11 23:12
Thomas.D Williams30-Aug-11 23:12 
AnswerRe: Per Pixel Access in C# winforms Pin
BobJanova30-Aug-11 4:36
BobJanova30-Aug-11 4:36 
GeneralRe: Per Pixel Access in C# winforms Pin
Thomas.D Williams30-Aug-11 5:30
Thomas.D Williams30-Aug-11 5:30 
QuestionThis collection already contains an address with scheme http. There can be at most one address per scheme in this collection in 3.5 Pin
nitin_ion29-Aug-11 21:33
nitin_ion29-Aug-11 21:33 

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.