Directory Programming .NET

Active Directory and ADAM programming support for .NET developers
Welcome to Directory Programming .NET Sign in | Join | Help
in Search

SDS.P Connection Caching...

Last post 09-07-2010, 2:05 PM by Jojer. 5 replies.
Sort Posts: Previous Next
  •  12-19-2007, 11:26 PM 2287

    SDS.P Connection Caching...

    I am working on a ASP.Net 2.0 Help Desk Application that resets passwords.  Per Chapter 8 Security in Directory Services Programming book, I planned on using an application pool configured with a identity that includes permissions to reset passwords.  I also planned on using SDS.P to do a simple find of the account and also to reset the passwords when needed.

    In earlier chapters (3?) you mention Connection Caching for ADSI.  Is there a similar construct for SDS.P?  If so, can you elaborate on how a ASP.Net web application could be configured/coded to take advantage of this?  If you know of any existing examples in this area I would be interested in that as well.  Go slow if you don't mind, I'm SDS.P challenged!

    BTW - I have almost worn out the cover of my Directory Programming .Net book.  This book has helped me more than any other book that I have purchased.  Thank you!

    Steve

  •  12-20-2007, 11:53 AM 2292 in reply to 2287

    Re: SDS.P Connection Caching...

    Good to hear (about the book).  There is no concept of connection caching in SDS.P.  Because you explicitly open/hold a connection in SDS.P via the LdapConnection class, you are in charge of any pooling or reuse.

    For an ASP.NET app, I am not sure how you would handle this easily (and btw, ADSI has a similar problem here).  You can certainly get pooling to work in ADSI as long as you have a another DirectoryEntry with same credentials and AuthencationTypes in scope.  Given that a page request is only in scope for a fraction of a second, this typically didn't happen too much, so ADSI has the same issue.  The object on the page (even static ones) go out of scope each request and are created/destroyed.

    Without putting the connection objects in another service or something like this, I am not sure you will get the pooling you desire.

    Joe mentioned something about static classes once, maybe he has a technique that would work here in ASP.NET.

    So, short answer - you are on your own and ASP.NET is hard to pool anyways even in ADSI.

    Ryan Dunn
    Extemporaneous Mumblings
    The .NET Developer's Guide to Directory Services Programming
  •  12-20-2007, 1:33 PM 2298 in reply to 2292

    Re: SDS.P Connection Caching...

    You could do something simple and just use the singleton design pattern to create a static instance of a wrapper class that contains your LdapConnection object and your methods for finding users and resetting passwords.  You would want to synchronize access to these methods with a sync block most likely.

    You could also do something very fancy and create your own pool of these objects.  Storing them in thread local storage would be one way to do that.

    While you are getting your feet wet, I suggest by starting simple.  Also remember that you need to be very careful when using any kind of static/shared instance in a web app as they are multithreaded by nature and can lead to thread safety bugs that are very hard to test for and diagnose if you are not careful.

    Let us know if you need more help than that.  I won't try to code this for you, but I can probably scare up a reference to a singleton pattern implementation and some references on multithreaded programming.

  •  12-20-2007, 2:37 PM 2301 in reply to 2298

    Re: SDS.P Connection Caching...

    It is safe to use the LdapConnection from multiple threads - so you shouldn't have to worry about.  The part of I am unsure of is that even if you created your own pool or used a Singleton, there has to be a instance running that roots the thing.  Since the ASP.NET page is created and destroyed in a single request, the rooting of any singleton or pool you create is going to disappear each request and it will defeat what you are trying to accomplish.  Contrast this to a forms application, where the running form can root any object for you.  Without going out of process, I don't know how you could fix this.

    Ryan Dunn
    Extemporaneous Mumblings
    The .NET Developer's Guide to Directory Services Programming
  •  12-20-2007, 2:48 PM 2302 in reply to 2301

    Re: SDS.P Connection Caching...

    Thanks for your replies; I appreciate it greatly.   I think the words that jumped out the most from this post is that I should start simple.  That in itself is a great reality check. 

    Steve

  •  09-07-2010, 2:05 PM 8538 in reply to 2302

    Re: SDS.P Connection Caching...

    seidensc: How did you solve the problem? Have you successfully implemented any connection pooling to your ASP.NET application? Im struggling with this problem right now, and im also a newbie to S.DS.P
View as RSS news feed in XML