Re: Windows Identity simple question ????



Hello,

the Thread.CurrentPrincipal.Identity does not necessarily contain the currently logged on user. Use WindowsIdentity.GetCurrent() for this (or, in case you are using ASP.NET with Integrated authentication but without impersonation, user HttpContext.Current.User).

Best regards,
Henning Krause

"calderara" <calderara@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:C7202059-F1F7-4AAC-89E0-35F88870E36E@xxxxxxxxxxxxxxxx
Dear all,

I am using .NEt.2.0 and trying to get the current identity in order to
retrive the role that my user belongs to.
For that I am using the following code

WindowsIdentity identity = (WindowsIdentity)Thread.CurrentPrincipal.Identity;
WindowsPrincipal pc = new WindowsPrincipal(identity);

When runing that code I hve a runtime excpetion saying that I have an
invalid cast.

identity is a WindowsIdentity object
Thread.CurrentPrincipal.Identity is retruning a GenericIdentity onject ???
which is strange becaseu the class definition says that Identity should
retrun an IIdentidy object but not a generic

What happen here ?

Thnaks for help
regards
serge

.



Relevant Pages

  • Re: WindowsAuthentication from code
    ... Logon using API call to get a token, create a new WindowsIdentity Object and ... > involving chalenge/response or basic authentication. ... > IsAuthenticated becomes true) but lasts only for the current request. ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: Impersonating when creating a process from inside a SQL Server Assembly
    ... WindowsIdentity is still WINDOWS SERVICE. ... Now, when you are inside a .NET assembly in SQL Server, you have access ... WindowsIdentity object that is the login user who called the stored ... WindowsIdentity.GetCurrentstill returns NT AUTHORITY/WINDOWS SERVICE. ...
    (microsoft.public.dotnet.security)
  • Re: Einfall... ;-)
    ... Returns a WindowsIdentity object that represents the!!!current Windows user!!!. ... Returns a WindowsIdentity object that represents the!!!Windows identity for either the thread or the process!!!, depending on the value of the ifImpersonating parameter. ...
    (microsoft.public.de.german.entwickler.dotnet.csharp)
  • Re: WindowsIdentity and Non-AD directory services
    ... active directory (say novell's eDirectory for whatever reason and ... users are authenticated against this non-AD directory services), ... does current WindowsIdentity object takes care of every thing I need ...
    (microsoft.public.dotnet.security)