简体   繁体   English

Active Directory:如何从登录控件中检索用户名和密码

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

I am using VS2005 C#. 我正在使用VS2005 C#。

I have a Login control on my web form and I am able to log in with correct credentials: 我的Web表单上有一个Login控件,并且能够使用正确的凭据登录:

I have no backend code which supports my Login control. 我没有支持我的Login控件的后端代码。

I am using Active Directory Authentication, and below is a code snippet of my AD in web.config : 我正在使用Active Directory身份验证,下面是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. 我已经在上面声明了一个有效的AD帐户。

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. 但是,当具有上述不同凭据的用户登录时,变量User.Identity.Name被标识为BTDP\\Jimmy而不是登录用户的用户名,尽管该用户输入的用户名和密码都经过了AD身份验证。

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? 我应该如何做才能使用户名和密码从网页的“ Login控件中输入连接字符串?

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. 这里博客可能会有所帮助,您可以尝试使用示例源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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