Active Directory Authentication

  • Thread starter Thread starter Mustafa Rabie
  • Start date Start date
M

Mustafa Rabie

Dear All,

I am writing a windows c# application, where it needs to make sure that the
currently logged on user is Active Dicrectory Authenticated. I looked on
the internet and found authentication for ASP.Net but not windows apps, can
someone point me to some code or links where i can find how this can be
reached?

Thanks
Mustafa
 
Mustafa Rabie said:
Dear All,

I am writing a windows c# application, where it needs to make sure that
the currently logged on user is Active Dicrectory Authenticated. I looked
on the internet and found authentication for ASP.Net but not windows apps,
can someone point me to some code or links where i can find how this can
be reached?

Thanks
Mustafa

If the current user is logged on using his domain credentials he is AD
authenticated, right.
So it's just a matter of checking his role membership.

AppDomain myDomain = Thread.GetDomain();
myDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
WindowsPrincipal myPrincipal =
(WindowsPrincipal)Thread.CurrentPrincipal;
try {
if( myPrincipal.IsInRole("(e-mail address removed)"))
// domain member and in role ("usergoroup" member)
else
// domain member but not in role (not a "usergroup" member)
}
catch(...) // If exception - CurrentPrincipal is no xxx.yyy.zzz
domain member

Willy.
 
Back
Top