Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.0 ASP.NET
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">
                                </forms>
             </authentication>-->
        <authorization>
            <deny users="?"/>
        </authorization>
 

      <identity impersonate="true"/>
 
        <membership defaultProvider="MyADMembershipProvider">
            <providers>
                <add name="MyADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider,         System.Web, Version=2.0.0.0, Culture=neutral,         PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ADConnection" attributeMapUsername="sAMAccountName"/>
            </providers>
        </membership>
        <profile>
            <providers>
                <clear/>
                <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
            </providers>
        </profile>
        <roleManager enabled="false">
            <providers>
                <clear/>
                <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/"/>
                <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/"/>
            </providers>
        </roleManager>
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
Edited 18-Sep-12 11:41am
v3

1 solution

Rate this: bad
good
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
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 328
1 Gihan Liyanage 292
2 Sergey Alexandrovich Kryukov 275
3 ClimerChinna 222
4 Abhinav S 187
0 Sergey Alexandrovich Kryukov 8,213
1 OriginalGriff 7,089
2 CPallini 2,598
3 Richard MacCutchan 1,925
4 Abhinav S 1,778


Advertise | Privacy | Mobile
Web04 | 2.8.140826.1 | Last Updated 18 Sep 2012
Copyright © CodeProject, 1999-2014
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