• <tfoot id='p2jVj'></tfoot>

      <i id='p2jVj'><tr id='p2jVj'><dt id='p2jVj'><q id='p2jVj'><span id='p2jVj'><b id='p2jVj'><form id='p2jVj'><ins id='p2jVj'></ins><ul id='p2jVj'></ul><sub id='p2jVj'></sub></form><legend id='p2jVj'></legend><bdo id='p2jVj'><pre id='p2jVj'><center id='p2jVj'></center></pre></bdo></b><th id='p2jVj'></th></span></q></dt></tr></i><div id='p2jVj'><tfoot id='p2jVj'></tfoot><dl id='p2jVj'><fieldset id='p2jVj'></fieldset></dl></div>

      <small id='p2jVj'></small><noframes id='p2jVj'>

        <bdo id='p2jVj'></bdo><ul id='p2jVj'></ul>
      <legend id='p2jVj'><style id='p2jVj'><dir id='p2jVj'><q id='p2jVj'></q></dir></style></legend>

      1. 使用 ASP.NET 获取 Active Directory 信息,无需用户名和密码

        时间:2023-10-24

        <tfoot id='gnzD0'></tfoot>

        <legend id='gnzD0'><style id='gnzD0'><dir id='gnzD0'><q id='gnzD0'></q></dir></style></legend>

        <small id='gnzD0'></small><noframes id='gnzD0'>

                <tbody id='gnzD0'></tbody>
                <bdo id='gnzD0'></bdo><ul id='gnzD0'></ul>
                  <i id='gnzD0'><tr id='gnzD0'><dt id='gnzD0'><q id='gnzD0'><span id='gnzD0'><b id='gnzD0'><form id='gnzD0'><ins id='gnzD0'></ins><ul id='gnzD0'></ul><sub id='gnzD0'></sub></form><legend id='gnzD0'></legend><bdo id='gnzD0'><pre id='gnzD0'><center id='gnzD0'></center></pre></bdo></b><th id='gnzD0'></th></span></q></dt></tr></i><div id='gnzD0'><tfoot id='gnzD0'></tfoot><dl id='gnzD0'><fieldset id='gnzD0'></fieldset></dl></div>
                • 本文介绍了使用 ASP.NET 获取 Active Directory 信息,无需用户名和密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试从 ASP.NET Web 应用程序获取本地网络上用户的 Active Directory 信息.Web 应用程序在本地网络上的 IIS 上运行.

                  I am trying to get users' Active Directory information on the local network, from an ASP.NET Web Application. The Web Application is running on an IIS on the local network.

                  我想要的:当用户登录网站时,他们可以从 Active Directory 中看到他们的姓名、姓氏、用户名、电子邮件和图片.问题是,当他们进入他们的网站时,Web 应用程序要求输入用户名和密码.用户在打开 PC 时已经输入了用户名和密码.所以他们不应该再这样做了.

                  What I want: When users log into the website, they can see their name, surname, username, email and picture from Active Directory. The problem is, when they enter their website, the web application is asking for username and password. Users have already entered their username and password when turning on their PCs. So they shouldn't need to do it again.

                  用户使用其用户名和密码登录 PC.我可以通过以下方式获取域和用户名:

                  Users login to PCs with their username and password. I can get domain and username with:

                  string adInfo = Request.ServerVariables["LOGON_USER"];
                  

                  在测试 System.DirectoryServices 时,我还可以在调试时在本地 PC 上获取 Active Directory 信息,但是当其他用户在本地尝试此 Web 应用程序时,会出现用户名和密码对话框.

                  Also I can get Active Directory info on my local PC on debug when testing System.DirectoryServices, but when other users try this web app in local, the username and password dialog appears.

                  我怎样才能让用户无需输入用户名和密码就可以进入他们的网站?

                  How can I make it so that users are able to enter their website without entering their username and password?

                  我在这里尝试了所有示例,但找不到任何解决方案.我想我错过了一些重要的事情.

                  I tried all samples here, but I can not find any solution. I think I am missing some important things.

                  推荐答案

                  您需要为您的网站使用 Windows 身份验证模式.

                  you need to use Windows authentication mode for your website.

                  <system.web>
                      <authentication mode="Windows" />
                      <authorization>
                          <deny users="?" /> <!-- disable anonymous authentication -->
                      </authorization>
                  </system.web>
                  

                  ...然后在当前用户的上下文中使用 LDAP 查询来获取有关用户的扩展信息:

                  ... and then use LDAP query under current user's context to get extended information about the user:

                  using System.DirectoryServices;
                  
                  using (var de = new DirectoryEntry("LDAP://DC=MYDOMAIN,DC=COM"))
                  using (var ds = new DirectorySearcher(de))
                  {
                    ds.Filter = string.Format("(sAMAccountName={0})", HttpContext.Current.User.Identity.Name);
                    ds.PropertiesToLoad.AddRange(new [] {
                              "sn",  // last name
                              "givenName",  // first name
                              "mail",  // email
                              "telephoneNumber",  // phone number
                              // etc - add other properties you need
                              });
                    var res = ds.FindOne();
                  
                    foreach (string propName in res.Properties.PropertyNames)
                    {
                      ResultPropertyValueCollection valueCollection = res.Properties[propName];
                      foreach (Object propertyValue in valueCollection)
                      {
                           Console.WriteLine("Property: " + propName + ": " + propertyValue.ToString());
                      }
                    }
                  }
                  

                  这篇关于使用 ASP.NET 获取 Active Directory 信息,无需用户名和密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何检查用户是否存在于 LDAP 上 下一篇:如何为 LDAP+SSL 连接验证服务器 SSL 证书

                  相关文章

                  1. <small id='U2Xoh'></small><noframes id='U2Xoh'>

                    <i id='U2Xoh'><tr id='U2Xoh'><dt id='U2Xoh'><q id='U2Xoh'><span id='U2Xoh'><b id='U2Xoh'><form id='U2Xoh'><ins id='U2Xoh'></ins><ul id='U2Xoh'></ul><sub id='U2Xoh'></sub></form><legend id='U2Xoh'></legend><bdo id='U2Xoh'><pre id='U2Xoh'><center id='U2Xoh'></center></pre></bdo></b><th id='U2Xoh'></th></span></q></dt></tr></i><div id='U2Xoh'><tfoot id='U2Xoh'></tfoot><dl id='U2Xoh'><fieldset id='U2Xoh'></fieldset></dl></div>
                      <bdo id='U2Xoh'></bdo><ul id='U2Xoh'></ul>
                    <tfoot id='U2Xoh'></tfoot>

                    1. <legend id='U2Xoh'><style id='U2Xoh'><dir id='U2Xoh'><q id='U2Xoh'></q></dir></style></legend>