Losing Windows Authentication intermittently
- by Mark Robinson
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.