Archive for tag: .NET

Authenticate a user to AD or AD LDS with C#

Since the .NET 3.5 framework it's very easy to validate a user to an ADAM or AD LDS user store. The following lines of code is all you need:

var pc = new PrincipalContext(ContextType.ApplicationDirectory, "adserver:50000", "o=org,c=nl", ContextOptions.Negotiate, @"domain\user", "password");
Console.WriteLine("Connected to: {0}", pc.ConnectedServer);
var validUser = pc.ValidateCredentials("userToValidate", "passwordToValidate", ContextOptions.SimpleBind);
Console.WriteLine(validUser);

Note that the useraccount MUST be enabled (msDS-UserAccountDisabled = FALSE) and that userPrincipalName should be CN value. Otherwise the validatecredentials method always will return false.

FormatException: Guid should contain 32 digits with 4 dashes...

While doing some development on SharePoint solution deployment I encountered a strange behaviour. The following code gave me the "FormatException:Guid should contain 32 digits with 4 dashes" error:

SPFarm.Local.Solution["demo.wsp"].DeployedWebApplications;

Strange as I'm not even using a GUID in my code here. So a little breaking down led me to the conclusion that if you call the DeployedWebApplications property on a solution that is globally deployed you get this error.