Re: Einfall... ;-)

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi Frank,

> Das sollte auf jeden Fall helfen:
> WindowsIdentity id = WindowsIdentity.GetCurrent();
> WindowsPrincipal p = new WindowsPrincipal(id);

Dieses, wie auch Environment.Username ist hier
nicht zielführend.
Beide geben nicht den angemeldeten User wieder,
sondern nur den, der den Prozess besitzt (ganz grob gesagt).
Im Prinzip ist hier auf die User Session zuzugreifen.

....da hast du Recht... nach einigem Testen und einigen Recherchen im INet ermitteln alle im .Net Framework implementierten Methoden, insbesondere SystemInfo... Environment und WindowsIdentity.GetCurrent() die Benutzernamen des aktuellen Threads bzw. Prozesses.

Dem Trugschluss, dem ich aufgesessen bin, scheinen eine ganze Menge Anderer auch aufzusitzen... zumindest gibt es ne ganze Menge Postings im INet, die dieen Schluss zulassen...

Diese beiden Auszüge der MSDN2 Doku, tragen auch nicht gerade dazu bei, dass man dies richtig verstehen kann...

WindowsIdentity.GetCurrent()
Returns a WindowsIdentity object that represents the !!!current Windows user!!!.

siehe:
http://msdn2.microsoft.com/en-us/library/sfs49sw0.aspx

WindowsIdentity.GetCurrent(Boolean)
Returns a WindowsIdentity object that represents the !!!Windows identity for either the thread or the process!!!, depending on the value of the ifImpersonating parameter.

siehe:
http://msdn2.microsoft.com/en-us/library/x22bbxz6.aspx

Tja... und wieder etwas dazu gelernt... danke!

Gruß Carl

.



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: Windows Identity simple question ????
    ... WindowsIdentity identity = Thread.CurrentPrincipal.Identity; ... identity is a WindowsIdentity object ... Thread.CurrentPrincipal.Identity is retruning a GenericIdentity onject ??? ...
    (microsoft.public.dotnet.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: 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)