Losing Windows Authentication intermittently

Posted by Mark Robinson on Server Fault See other posts from Server Fault or by Mark Robinson
Published on 2011-01-17T12:02:00Z Indexed on 2011/01/17 12:55 UTC
Read the original article Hit count: 288

I'm running a website on IIS6 / Server 2003 which uses Integrated Windows Authentication on a local intranet. I can browse to the site but get intermittent "Object null" errors when calling the following C# code which is called on every request:

....
GetUserIdFromPrincipal(User)
....

public static string GetUserIdFromPrincipal(IPrincipal principal)
{
    return principal.Identity is WindowsIdentity ? (principal.Identity as WindowsIdentity).User.Value : principal.Identity.Name;
}

(Apologies for the code sample but was torn between SF and SO but think this is more to do with server config).

So as the error is intermittent clearly Windows Auth is working on some level but after navigating around the site for several clicks I get the null reference error meaning IPrincipal is null (I thought this should never be null in ASP.NET).

The error only happens on this newly built VM. The code is fine on other machines.

Does IIS request the Windows Auth details on each request? What would cause such an intermittent problem? Any help or suggestions would be much appreciated.

© Server Fault or respective owner

Related posts about windows-server-2003

Related posts about iis6