tags:

views:

30

answers:

1

In ASP.NET or WCF is it safe to use ServiceSecurityContext.Current.WindowsIdentity.Nameto get the current username that executes the current thread?

I want to ensure that the correct user is impersonated in my WCF Service.

+2  A: 
WindowsIdentity.GetCurrent().Name

is probably a better alternative, as I don't think that ServiceSecurityContext.Current is available in ASP.NET.

You may also want to consider

Thread.CurrentPrincipal.Identity.Name

if you care about the user instead of the process identity.

Mark Seemann
The Weird thing is that when I create a file, the owner is "Administrators", which is Very weird because when I use windows authentication with impersonation rather than forms authentication with impersonation, the owner is the domain user that I am logged in as. But both of the Above tells me the correct username. Are you sure that these are the "final"/"only" credentials AppPool is executed with?
Filip Ekberg