我可以从本地服务器上的活动目录组中检索所有用户名,但在IIS上显示异常错误

时间:2013-04-23 10:52:57

标签: iis permissions active-directory

我是stachoverflow的新用户,我正在开发一个用于Intranet的Web应用程序,在该应用程序中,它从活动目录验证用户,这在IIS上工作正常,但是我遇到了从活动目录组中检索数据(所有用户名)的问题。在本地服务器上正常工作。         在IIS上它提供异常错误 - System.DirectoryServices.DirectoryServicesCOMException:登录失败:未知的用户名或密码错误。 在IIS Windows身份验证启用和其他已禁用

My code is:
Web.config file:
<authentication mode="Windows">
            <forms loginUrl="~/TTracker/Login.aspx" timeout="600"></forms>
        </authentication>

<authorization>
            <deny users="?"/>
            <allow users="*" />


        </authorization>
    <identity impersonate="true" />


Code for retrieving data:

using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;
using (HostingEnvironment.Impersonate())
            {
                DropDownList1.Items.Add(new ListItem("-Select-", ""));
                string grpname = "Group1";                
                PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "domain");
                GroupPrincipal grp = GroupPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, grpname);
                if (grp != null)
                {
                    foreach (Principal p in grp.GetMembers(false))
                    {
                        DropDownList1.Items.Add(p.SamAccountName + "-" + p.DisplayName);

                    }
                    grp.Dispose();
                    ctx.Dispose();
                    Console.ReadLine();
                }
                else
                {
                    Console.WriteLine("We did not find that group.");
                    Console.ReadLine();
                }
            }


this is my code for retrieving data from active directory which works fine locally but not works on IIS.

It will be great help if any one solve this issue.

Thanks in advance.

1 个答案:

答案 0 :(得分:0)

这与假冒有关。

请检查以下内容,

我们可以冒充帐户来处理AD。

ASP.NET模拟 http://msdn.microsoft.com/en-us/library/aa292118(VS.71).aspx 并阅读此文档。

Howto :(几乎)通过C#在Active Directory中的一切 http://www.codeproject.com/KB/system/everythingInAD.aspx