Click here to Skip to main content
15,880,796 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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.
Posted
Updated 23-Apr-13 4:22am
v3
Comments
ZurdoDev 23-Apr-13 10:23am    
The error tells you it is a permissions issue.
chetan hakke 24-Apr-13 1:33am    
if it is permission issue then how to give permission to all users on intranet using windows authentication
chetan hakke 24-Apr-13 1:37am    
I can't access this page only with code of retrieve data from active directory on IIS, other pages of application i can access on IIS even authentication against active directory also works good.

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900