From: Tony Johansson on
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


From: Willem van Rumpt on
On 16-6-2010 19:06, Tony Johansson wrote:
> 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.

--
Willem van Rumpt