views:

40

answers:

1

I want to get currently logged in active directory user name/details.

Here, User does log in to machine with its AD username and password. How can i get this user name and other details in Global.asax file for Application_AuthenticateRequest() Event.

I have used System.Security.Principal.WindowsIdentity.GetCurrent().Name But, when it hosted on IIS 6.0 returns Server's users credentials. such as "domain\username". I have currently enabled Anonymous Access and Integrated Authentication. And in project using Form Authentication.

Should I use System.Directory.dll

+1  A: 

If you want the windows credentials, then you should disable anonymous access, and use windows security instead of forms authentication in your application.

You use HttpContext.User.Identity.Name to get the name of the logged in user inside your application. If you use forms auth, then you will get the name of the logged in forms-user, if you use integrated security and windows auth, then you get the AD name of the user.

Mikael Svenson
One More Thing, I am using personalization setting in my application, I have changed it as you told but it gives error "Personalization not enabled" and when I change it to Form Authentication in Application, it works but again restores IIS user name provided that Anonymous is Enabled. If I disable it It ask for user name and password for accessing application that i don't want. please reply.
Swapnil Fegade
To be clear, you want a user database with user profiles, but based on AD credentials, right?
Mikael Svenson
Thanks for reply. I have DB for user profiles and I want AD credentials (username), he/she entered when loged into system. Any Solution?...
Swapnil Fegade
Check this old blog post by ScottGu - http://weblogs.asp.net/scottgu/archive/2006/07/12/Recipe_3A00_-Enabling-Windows-Authentication-within-an-Intranet-ASP.NET-Web-application.aspx
Mikael Svenson