简体   繁体   中英

Active Directory : how to retrieve username and password from Login control

I am using VS2005 C#.

I have a Login control on my web form and I am able to log in with correct credentials:

I have no backend code which supports my Login control.

I am using Active Directory Authentication, and below is a code snippet of my AD in web.config :

<membership defaultProvider="MyADMembershipProvider">       
    <providers>
        <clear/>
            <add name="MyADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider, 
            System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" 
            applicationName="SOD" connectionStringName="ADConnectionString" 
            connectionUsername="BTDP\Jimmy" connectionPassword="p@ssww0rd"
            attributeMapUsername="sAMAccountName" enableSearchMethods="true" />
    </providers>
</membership>

I have declared a valid AD account above.

However, when a user of different credentials as the above logs in, the variable User.Identity.Name is identified as BTDP\\Jimmy instead of the username of the logged in user, although the username and password the user entered went through AD authentication.

May I know if I am wrong for hard coding the credentials in the connection string?

How should I do it so that I am able to pump in the username and password into the connection string from the Login control in the web page?

Not sure if this is something to do with either user impersonation or the fact that your application is querying the Domain Controller but impersonating as that user. The blog here might be helpful, has working example source you can try.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM