CurrentPrincipal for Thread seems to give wrong result

  • Thread starter Thread starter Tony Johansson
  • Start date Start date
T

Tony Johansson

Hello!

If I run the code below I get the following result
Name:
IsAuthenticated: False
AuthenticationType:

So I thought I would get the name I used when logging in to the computer and
that IsAuthenticated should be true because
the computer should Authenticate me when I logging into the computer.

Thread t = Thread.CurrentThread;
System.Security.Principal.IPrincipal threadPrincipal =
Thread.CurrentPrincipal;
Console.WriteLine("Name: {0}\nIsAuthenticated: {1}" +
"\nAuthenticationType: {2}",
threadPrincipal.Identity.Name,
threadPrincipal.Identity.IsAuthenticated,
threadPrincipal.Identity.AuthenticationType);

//Tony
 
Hello!

If I run the code below I get the following result
Name:
IsAuthenticated: False
AuthenticationType:

So I thought I would get the name I used when logging in to the computer and
that IsAuthenticated should be true because
the computer should Authenticate me when I logging into the computer.

Thread t = Thread.CurrentThread;
System.Security.Principal.IPrincipal threadPrincipal =
Thread.CurrentPrincipal;
Console.WriteLine("Name: {0}\nIsAuthenticated: {1}" +
"\nAuthenticationType: {2}",
threadPrincipal.Identity.Name,
threadPrincipal.Identity.IsAuthenticated,
threadPrincipal.Identity.AuthenticationType);

//Tony

The default identity settings don't assume anything about which
authority controls the indentity, and creates a default, unauthenticated
principal and identity.

To get what you expect (the windows login), set the principal policy to
PrincipalPolicy.WindowsPrincipal through AppDomain.SetPrincipalPolicy.
 
Back
Top