Reputation: 233
I am trying to get the windows username on an aspx page.
I have tried the following:
<% System.Threading.Thread.CurrentPrincipal = new System.Security.Principal.WindowsPrincipal(System.Security.Principal.WindowsIdentity.GetCurrent()) %>
<%= System.Threading.Thread.CurrentPrincipal.Identity.Name %>
But all that does is give me IIS APPPOOL/SBalance - which is not the windows username!
However if I add the following server control:
<asp:LoginName ID="LoginName1" runat="server" />
this does successfully pre-populate with my domain and username.
So how can I get the domain/username as a string on the aspx page without using a login control?
Thanks
Upvotes: 2
Views: 1396
Reputation: 7591
you will need to enable impersonation in the web.config
<identity impersonate="true" />
then you need to enable windows impersonation in IIS and disable anonymous authentication
Upvotes: 0
Reputation: 51674
If you use Windows Authentication you can get the username via User.Identity.Name
string windowsLogin = Page.User.Identity.Name;
Upvotes: 3