Today I would like to present you a simple ODATA search controller that you can use in LightSwitch (or any other ODATA consumer) to look up user accounts (and possibly other objects). When using SharePoint you will probably know the very convenient PeoplePicker. However, in LightSwitch (HTML) there is no equivalent to that. You certainly have “Person” objects/data types but no handy function to perform account lookup. With this controller you can easily implement that missing functionality. The controller is a very simple WebAPI based ODATA controller that only implements two functions

1. GetActiveDirectoryUsers()
as there is not much use to return ALL AD objects it currently only returns the current AD user that is logged on in LightSwitch.

2. GetActiveDirectoryUser()
this is the actual search function where the AD searcher tries to match against properties such as:


With ‘{0}’ the ‘key’ parameter that can contain wildcards if you specify them.
All other CRUD operations will return either HTTP 401 “NotAuthorized” or HTTP 501 “NotImplemented”.

You can use this controller as a regular LightSwitch ODATA source, and even better in combination with select2 and jaydata to query user information on the fly. Configuration data is currently read from the web.config and updated periodically.

If you want to search for all users with a name containing “admin” a query will actually look like this (you have to specify the wildcard characters manually):

An example response might look like this (returning two user objects):

You can download the sourcecode which is put under the Apache 2.0 license from our GitHub repository “biz.dfch.CS.ActiveDirectory.Search” at


  1. Excellent work!
    When runs locally everything is OK, but when published ActiveDirectoryUsers fails because key=Application.User.Name does not get value. Help with it please

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.