Click here to Skip to main content
13,087,235 members (55,743 online)
Rate this:
Please Sign up or sign in to vote.
See more:
I'm trying to retrieve to username of the loged user, but it keeps on giving me the name of only one user even though if I log in with a different account which should give me a different username..
in my web config file I gave:
<authentication mode="Windows" />
                <!--<forms loginUrl="Login.aspx" protection="All" path="/" timeout="2880">
            <deny users="?"/>

      <identity impersonate="true"/>
        <membership defaultProvider="MyADMembershipProvider">
                <add name="MyADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider,         System.Web, Version=, Culture=neutral,         PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ADConnection" attributeMapUsername="sAMAccountName"/>
                <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
        <roleManager enabled="false">
                <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/"/>
                <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/"/>

I have tried to use the following ways below but nothing worked. It again give me the same username:
string username = System.Web.HttpContext.Current.User.Identity.Name;
System.Security.Principal.WindowsIdentity user = System.Security.Principal.WindowsIdentity.GetCurrent();
Posted 18-Sep-12 11:04am
Updated 18-Sep-12 11:41am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Have a look at: Credentials and Delegation[^] for a few things that must be in place for this to work.

Try removing the stuff below
<identity impersonate="true"/>

WindowsIdentity.GetCurrent(); should return the user accessing your application through browsers supporting Integrated Windows Authentication - Firefox may cause some trouble, but Chrome and IE should work as long as everything is configured correctly. Remember that the IIS service user must be an AD user.

Best regards
Espen Harlinn

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170813.1 | Last Updated 18 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100