Friday, June 17, 2005

Getting the Windows User Identity


1) Add the following line in Web.config:

2) Set IIS access to Windows Authentication and disable anonymous access from IIS Management MMC Snap-in.

3) UserName= HttpContext.Current.User.Identity.Name;

Note: UserName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;" might also return the user name but there is a catch. If you define a static username and password in web.config then this code will always return the name in the web.config. However httpcontext returns the actual user name.

No comments: