Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Team,

It is really urgent I want to implement LDAP validation in my web application
As we are login with citirx VM and enter the username & Password then access intanet application in this application we need to valdiate the user through LDAP and do not want to ask user credential without asking credential checked in LDAP if user is exist in LDAP so he is able to access and by pass the user to Home page else display message user not authorized ..


Please advice how can be implement..Currently I have use below piece of code this code validate in my local but when i deoply the code in IIS it is not working and throwing error in IIS level below sttings done configuration
Authentication:
Windows Authentication: Enabled
Asp.net Impersonation:Enabled
Anonymous Authentication: Disabled

----------------------------------
PLEASE ADVICE HOW CAN BE IMPLELMENT IT IS REALLY URGENT WE NEED TO MET DEADLINE
-----------------------------------------
IUSRNT AUTHORITY
Hello .
You are not authenticated using .
--------------------------------------------

COde
-----------------------------------------------------
C#
bool validation;
            try
            {

                LdapConnection lcon = new LdapConnection(new LdapDirectoryIdentifier((string)null, false, false));

                NetworkCredential nc = new NetworkCredential(Environment.UserName, "welcome6citi@", Environment.UserDomainName);
                Response.Write(nc.UserName.ToString());
                Response.Write(nc.Domain.ToString());

                lcon.Credential = nc;
                lcon.AuthType = AuthType.Negotiate;
                lcon.Bind(nc); // user has authenticated at this point, as the credentials were used to login to the dc.
                validation = true;
            }
            catch (LdapException)
            {
                validation = false;
            }
            if (validation)
            {
                Response.Redirect("Home.aspx");

            }
            else
            {

                lblName.Text = "Hello " + Context.User.Identity.Name + ".";
                lblAuthType.Text = "You are not authenticated using " + Context.User.Identity.AuthenticationType + ".";

            }
Posted
Updated 10-Mar-15 0:26am
v2
Comments
[no name] 10-Mar-15 6:22am    
Please note that we are volunteers here. No one here is getting paid for answering questions. So we have our own schedule and what's urgent to you, isn't urgent to us. Some may even refrain from answering you when you try to hurry them.
ZurdoDev 10-Mar-15 7:24am    
1. Stop yelling.
2. If it works local but doesn't work in IIS on the server don't you think your code is fine and the problem is with IIS? So, give us the error you were getting.
deepika1 10-Mar-15 12:35pm    
While running the application in IIS below error is showing

LDAPIIS APPPOOL

Hello .
You are not authenticated using .
---------------------------------------------
I have used below piece of code :

LdapConnection lcon = new LdapConnection(new LdapDirectoryIdentifier((string)null, false, false));

NetworkCredential nc = new NetworkCredential(Environment.UserName, "welcome6citi@", Environment.UserDomainName);
Response.Write(nc.UserName.ToString());
Response.Write(nc.Domain.ToString());

lcon.Credential = nc;
lcon.AuthType = AuthType.Negotiate;
lcon.Bind(nc); // user has authenticated at this point, as the credentials were used to login to the dc.
validation = true;

-----------------------------------
As we are passing "Password" Hardcode because I am not able to understand how can we pass the passowrd as per my undersntding in first attemp when we login that time capture the username and password
Kornfeld Eliyahu Peter 10-Mar-15 8:26am    
To ask LDAP questions about other users the user asking must have certain permissions too...
Probably the user runs your site under IIS missing those permissions...
deepika1 10-Mar-15 12:37pm    
If possible please share the setting at IIS level because as per requriemnet if user is exist directly by pass the Home page not asking credential

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