Solved

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

Posted on 2013-01-15
11
901 Views
Last Modified: 2013-01-17
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
Comment
Question by:mikesExpertExchange
11 Comments
 
LVL 52

Assisted Solution

by:Scott Fell, EE MVE
Scott Fell,  EE MVE earned 167 total points
ID: 38781359
0
 
LVL 13

Assisted Solution

by:agarwalrahul
agarwalrahul earned 166 total points
ID: 38781435
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
 
LVL 1

Author Comment

by:mikesExpertExchange
ID: 38783965
@agarwalrahul: where does this line go:

<identity impersonate="true"/>

?

I'm getting an: "Unrecognized element" at compile time. Do I need it?
0
The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

 
LVL 41

Accepted Solution

by:
guru_sami earned 167 total points
ID: 38783982
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
 
LVL 1

Author Comment

by:mikesExpertExchange
ID: 38784500
@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
 
LVL 41

Expert Comment

by:guru_sami
ID: 38784518
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
 
LVL 1

Author Comment

by:mikesExpertExchange
ID: 38785088
@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
 
LVL 41

Expert Comment

by:guru_sami
ID: 38785136
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
 
LVL 1

Author Comment

by:mikesExpertExchange
ID: 38785791
@guru_sami: Do you know if putting the port number in the connection string is required?
0
 
LVL 41

Expert Comment

by:guru_sami
ID: 38788377
No it is optional. Default is 389 for non-ssl and 636 for ssl. More info.
0
 
LVL 1

Author Closing Comment

by:mikesExpertExchange
ID: 38788518
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MailAddress in vb 4 29
Amazon S3 Images with .Net 3 15
Amazon S3 .Net error 5 21
Data organization issue 7 22
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question