0

I have been messing with this all night and it is really frustrating. I got the webpage to display finally but for some reason it is not working meaning that it shoots me back to my error page and states "Could Not Authenticate User Please Try Again!". I cant figure this out as this works perfectly find on my local machine that visual studios is installed on.

Please if someone can take the time to help out with this, ive been fighting with it all day. THanks

Class.cs

public bool IsUserInSetup(string groupName, UserPrincipal user)
    {
        PrincipalContext context = new PrincipalContext(ContextType.Domain, "DomainName");
       GroupPrincipal group = GroupPrincipal.FindByIdentity(context, "GroupName");

        if (user.IsMemberOf(group))
        {
            return true;
        }
        return false;
    }

Authentication.aspx.cs

 if (!IsPostBack)
            {
                if (Request.IsAuthenticated)
                {

                    if (gv.IsUserInSetup("GroupName", user))
                    {
                        Session["userValue"] = UserPrincipal.Current;

                        Response.Redirect("Default.aspx");

                    }
 else
                {
                    lblInfo.Text = "Could Not Authenticate User Please Try Again!";
                    lblInfo.Text += "<br><b>Name: </b>" + User.Identity.Name;
                    lblInfo.Text += "<br><b>Authenticated With: </b>";
                    lblInfo.Text += User.Identity.AuthenticationType;
                }
0

2 Answers 2

1

Once possible reason why the application might be failing when deployed on IIS is because the account you configured it to run under doesn't have sufficient privileges to access the Active Directory server. By default the application pool in IIS runs under a built-in ApplicationPoolIdentity account which is a local to the server account. You should go to the settings of the application pool in IIS and select a domain account with sufficient privileges.

This works when running locally in VS because you are running your application with your account which is probably a domain account with access to Active Directory.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the response I created an application pool and used Domain\Admin credentials and still the same story. I noticed if I dont have impersonation enabled I get the following error? Unable to cast object of type 'System.DirectoryServices.AccountManagement.GroupPrincipal' to type 'System.DirectoryServices.AccountManagement.UserPrincipal'.
0

Got the answer on another forum but I was doing a lot of extra work for no reason. Asp.net has a USER.ISINROLE("GROUPNAME") and i used that.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.