我可以从本地服务器上的活动目录组中检索所有用户名,但在IIS上显示异常错误 [英] I can retrieve all user names from active directory group on local server but on IIS showing exceptional error

查看:132
本文介绍了我可以从本地服务器上的活动目录组中检索所有用户名,但在IIS上显示异常错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我的代码是:

Web.config文件:

< ; authentication mode =Windows> 
< forms loginUrl =〜/ TTracker / Login.aspxtimeout =600>< / forms>
< / authentication>

<授权>
< deny users =?/>
< allow users =*/>


< / authorization>
< identity impersonate =true/>



检索数据的代码:

使用的System.DirectoryServices; 
使用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(校长p in grp.GetMembers(false))
{
DropDownList1.Items.Add(p.SamAccountName) + - + p.DisplayName);

}
grp.Dispose();
ctx.Dispose();
Console.ReadLine();
}
else
{
Console.WriteLine(我们没有找到那个组。);
Console.ReadLine();
}
}





这是我从活动目录中检索数据的代码,在本地工作正常但不起作用在IIS上。



如果有人解决这个问题,将会很有帮助。



提前致谢。

解决方案

检查这个

如何使用ASP.NET中的System.DirectoryServices命名空间 [ ^

I am new user for stachoverflow, I am developing one web application for intranet in which it authenticate user from active directory which works fine on IIS but I am getting problem to retrieve data(all user names) from group of active directory which works fine on local server. on IIS it gives exceptiona error- System.DirectoryServices.DirectoryServicesCOMException: Logon failure: unknown user name or bad password. in IIS windows authentication enabled and other are disabled.

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.

解决方案

Check this
How to use the System.DirectoryServices namespace in ASP.NET[^]


这篇关于我可以从本地服务器上的活动目录组中检索所有用户名,但在IIS上显示异常错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆