I’m trying to trace an application error and I’m no whiz on the WinNT provider side. Here’s the code I’m debugging:
public string GetCurrentRequesterIdentity()
{
var a = HttpContext.Current.User.Identity.Name.Split('\\');
using (var adEntry = new DirectoryEntry("WinNT://" + a[0] + "/" + a[1]))
{
return adEntry.Properties["FullName"].Value.ToString();
}
}
When I debug this code and run “? New DirectoryEntry(“WinNT://DOMAIN/User”)” where DOMAIN and User are (supposedly) valid entries, the window returns the following for the ObjectSecurity line:
ObjectSecurity: ‘new DirectoryEntry(“WinNT://[DOMAIN]/[USER]”).ObjectSecurity’ threw an exception of type ‘System.NullReferenceException’
I’ve seen the application throw an error of “The network path was not found.” I have only been able to replicate this error once and not again. Unfortunately, it happens almost every time for 2 production users, but never happens in the test environment.
Has anyone seen this situation before? Or know where to look to track it down?
This ended up getting fixed by removing the DirectoryEntry line and instead referencing just the HttpContext.Current.User.Identity.Name.Split(‘\’) for the username. It doesn’t matter that it only returns the username rather than the full name of the logged on user. Apparently it related to a permissions issue with AD that our system admins would rather not deal with, so removing the code ended up providing the simplest solution.