Freigeben über


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,
password,
domain);

    // 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

Disclaimers:
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