Novell Home

AppNote: Moving a .NET C# LDAP Browser Application to Mono on Linux

Novell Cool Solutions: AppNote
By Michel Bluteau

Digg This - Slashdot This

Posted: 19 Nov 2004

This article provides an example for porting an application developed with Microsoft Visual Studio.NET to mono. For this example, I have decided to create a primitive LDAP browser application with a GUI in Visual Studio.NET to also illustrate how to interface .NET C# with Novell eDirectory. C# has been used instead of VB.NET since it is easier to port to mono.

We have to go through three steps:

  1. Find an example C#.NET application that leverages System.DirectoryServices for Active Directory, and modify it to point to eDirectory.
  2. Build/Compile in Release Configuration mode in Visual Studio.NET.
  3. Move the compiled application to mono, assuming that mono has been pre-installed either through a rpm or red carpet (I used red carpet for mine).

Step 1: Find an example C#.NET application.

I basically used Google to search the web with keywords like c#, active directory and System.DirectoryServices. There are tons of examples and code snippets out there, and the one I have started from for my example is available through:

Viewing Active Directory Objects via ASP.NET
Date: Monday, July 15, 2002
Author: Erick Sgarbi

Most of the examples out there are designed to work against Active Directory and leverage Windows authentication through the domain, assuming that the Visual Studio Framework and IIS are running on a server that is part of the domain. But it is usually easy to tweak the code so it performs a LDAP serverbind instead using a DirectoryEntry like this:

DirectoryEntry("LDAP://,o=novl,c=ca","cn=admin,o=novl, c=ca","password", System.DirectoryServices.AuthenticationTypes.ServerBind);

A few more things need to be adjusted, like limiting the attributes that are being returned by a query because some attributes types are not yet supported by System.DirectoryServices. On mono, one could leverage the eDirectory class to overcome these limitations.

The example (you can download the source from the link on this page) features 3 forms (WebForm1-WebForm3) that illustrate 3 different Web interfaces. WebForm2 is the most interesting one, since it is interactive and graphical.

Figure 1: Simple static LDAP query form with no GUI.

Figure 2: Another simple static form that lists attributes for users.

Figure 3: Interactive graphical LDAP application/form running from Windows/IIS.

Figure 4: Interactive graphical form browsing user record NJones.

Figure 5: Interactive graphical form browsing record PMetheny.

In the example, I am using a binddn with admin as the account. It is fairly easy in Visual Studio.NET to setup a form to query for the credentials instead of hard coding them in the code. One could also use anonymous or a proxy user with limited rights.

Step 2: Build/Compile in Release Configuration mode in Visual Studio.NET.

Files generated by Visual Studio.NET can be found in two locations, one for the project files, and one for the published application.

Figure 6: Project files under My Documents.

Figure 7: Published project files under C:\Inetpub\wwwroot.

If you download the source file and decide to copy them on your Windows server, make sure you properly set the directory under IIS to be an application:

Figure 8: IIS Manager for the default web site.

Figure 9: Add application name for the WebApp1 directory under wwwroot.

Figure 10: Select configuration manager under Build in Visual Studio.NET.

Figure 11: Select Release for the Project.

Step 3: Move the compiled application to mono.

In order to execute the application from mono, one simply has to copy the published application files from under C:\Inetpub\wwwroot\WepApp1 to a location under the root for the mono web server.

Figure 12: Published application directory to copy to Linux server.

Figure 13: Destination mono web server directory under /root/mono.

Figure 14: Starting the mono xsp server by providing the app directory as the root directory for simplicity.

Figure 15: Accessing WebForm2 from the mono server on Linux.

That was easy, wasn't it! That's all there is, a simple copy.

I have seen documents which seem to indicate that a recompile is required once the project files are copied to Linux. While this wouldn't hurt, this is not necessary and the WebApplication1.dll created by Visual Studio.NET seems to run just fine on Linux. Here is the script that would allow one to recompile:

#! /bin/bash

mcs /t:library /out:bin/WebApplication1.dll -r:System.Web -r:System.Xml -r:System.Data -r:System.Drawing -r:System.DirectoryServices AssemblyInfo.cs WebForm1.aspx.cs WebForm2.aspx.cs WebForm3.aspx.cs Global.asax.cs

The above script would need to be executed from the WebApp1 directory. But again, it was not necessary in my case.


While I have been using Visual Studio for developing my application, it would have been possible for someone to use another tool, for example MonoDevelop:

Figure 16:
Figure 16: MonoDevelop on Linux (start monodevelop).

MonoDevelop is improving rapidly and is becoming a powerfull development tool. The reason why I used Visual Studio instead was to demonstrate how easy it is for someone who is already familiar with Visual Studio and .NET to still use Visual Studio to develop applications, or to port existing applications to mono.

I hope that you have found this article useful. Please, do not hesitate to provide me with feedback and comments. Thanks.

Download - the files which constitute the C# application.

Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions.

© 2014 Novell