• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 921
  • Last Modified:

How do I authenticate against an LDAP in my ASP .NET web application?

I'm looking for examples of authenticating against and LDAP with a username and password in a ASP .NET [C#] web application. Can someone give me sample code or point me to links of such examples?
0
Michael Sterling
Asked:
Michael Sterling
3 Solutions
 
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
0
 
Rahul AgarwalTeam LeaderCommented:
Code

Put these sections in Web.config <configuration><configSections></configSections></configuration>

<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
                              
<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>

<identity impersonate="true"/>

and in Code Part on aspx Page

using System.Security;
using System.Security.Principal.WindowsIdentity;

Please Look into Link:

http://www.codeproject.com/Articles/18102/Howto-Almost-Everything-In-Active-Directory-via-C#35
0
 
Michael SterlingWeb Applications DeveloperAuthor Commented:
@agarwalrahul: where does this line go:

<identity impersonate="true"/>

?

I'm getting an: "Unrecognized element" at compile time. Do I need it?
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
guru_samiCommented:
Here's something I have used once:
http://www.beansoftware.com/ASP.NET-Tutorials/Forms-Authentication-Active-Directory.aspx

Make sure you have right connectionstring to your ldap server.
0
 
Michael SterlingWeb Applications DeveloperAuthor Commented:
@guru_sami: How do I know if I need to add anything else to the connections string other than the url that I was given? What would I need to get the answers that I need?
0
 
guru_samiCommented:
It is not mandatory to have something...if it's just the url, then it it should work as well.
Your IT admin might know more on it...
0
 
Michael SterlingWeb Applications DeveloperAuthor Commented:
@guru_sami: if all my pieces are correct, would me attempting to connect through my localhost/ return me an error of:

"Logon failure: unknown username or bad password."
0
 
guru_samiCommented:
Ideally it shouldn't. Try debugging and see if there are any exceptions related to connection to ldap or it is connecting but not able to find the user for any reason.
0
 
Michael SterlingWeb Applications DeveloperAuthor Commented:
@guru_sami: Do you know if putting the port number in the connection string is required?
0
 
guru_samiCommented:
No it is optional. Default is 389 for non-ssl and 636 for ssl. More info.
0
 
Michael SterlingWeb Applications DeveloperAuthor Commented:
Thank you all for your input and help. Turns out the user had given me incorrect credentials. Which I kind of knew based on the error message I was getting but they insisted that they were correct. Or rather didn't look close enough initially to verify.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Tackle projects and never again get stuck behind a technical roadblock.
Join Now