NTLM authentication support in NetCF

Many folks have asked the .NET Compact Framework team when our HTTP client was going to support NTLM authentication.  For version 1 (and all service packs) our answer was: 'Sorry, we do not support NTLM.  You may wish to locate a third party solution or write the auth code yourself...'.  Not too cool.

With the beta 1 release of NetCF version 2, NTLM support is here!

If you have previously protected your web site / service using Digest authentication, all you need to do is enable NTLM on your server, install NetCF v2 on your clients and you'll authenticate using NTLM.  As long as your client application collects credentials from the user and places them into a NetworkCredential object, you're set.  The HTTP client will authenticate using whichever is the most secure method (Negotiate, NTLM, Digest, Basic) supported by the server.  The code fragment, below, shows the construction and use of a NetworkCredential object.

using System.Net;

public void SetCredentials(HttpWebRequest request,
                           String userName,
                           String password,
                           String domain)
    // construct the credentials object
    NetworkCredential credentials = new NetworkCredential(userName,

    // set the credentials on the request
    request.Credentials = credentials;

Nothing to it!  Your client will now authenticate to your server using the most secure method available. 

Please note, if your device has NetCF v1 and v2 installed, you must target your application to version 2 for NTLM authentication to occur.  This can be done by:

  1. Building your application against the v2 beta
  2. Uninstall v1 from your device (not possible on PPC 2003 devices, as v1 is installed in ROM)
  3. Construct an application configuration file for your executable, instructing it to run against the v2 beta

Option 1 is the simplest and ensures that your application always has NTLM support available.
Options 2 and 3 provide NTLM support for existing applications by retargeting them to the NetCF v2 runtime.  (I will talk more about application configuration file support in NetCF v2 in a future post.)

-- DK

This posting is provided "AS IS" with no warranties, and confers no rights.
Some of the information contained within this post may be in relation to beta software.  Any and all details are subject to change.

Comments (6)

  1. Mike W. says:

    Where can I get CFv2 beta? How do I build an app config file to get my app to use CF v2?


  2. David Kline says:

    Mike W., Good questions! Thanks for reminding me to post that information. Please see http://blogs.msdn.com/davidklinems/archive/2004/08/03/207362.aspx for where to get the NetCF v2 beta and http://blogs.msdn.com/davidklinems/archive/2004/08/03/207372.aspx for how to build the app config file.

    — DK

  3. Mike W. says:

    Thanks for the help so far. How do you do your Option 1 (build the app against the v2 beta)?

  4. David Kline says:

    Mike W., You can either build using the Visual Studio 2005 beta (easiest method) or you can build from the command line / makefile (I plan on posting info on how to do this soon).

    — DK

Skip to main content