Reputation: 131
If I have a basic web form for our company's intranet and all users are logged in to the domain via AD authentication, can I extract a visitors user name in c#?
Upvotes: 2
Views: 805
Reputation: 124716
If you are using Windows Authentication, and don't allow anonymous access, then HttpContext.Current.User.Identity.Name
will have the name of the currently logged on user in the format domain\username
.
If you want more info from AD (e.g. a display name), then you need to use the classes in the System.DirectoryServices
namespace. You may need to provide credentials to access AD if your site is running under a restricted account such as the Network Service account.
Upvotes: 1
Reputation: 532475
Use the User
property on the current Page, like so,
var username = this.User.Identity.Name
Upvotes: 1