I am running a website on IIS6 / Server 2003 that uses integrated Windows authentication on a local intranet. I can go 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;
}
Since the error is intermittent, it is obvious that Windows Auth works at some level, but after navigating the site in a few clicks I get a zero link error, that is, IPrincipal is null (I thought it should never be empty in ASP .NET).
The error only occurs on a newly built virtual machine. The code is great for other machines and, of course, when developing locally.
Does IIS request Windows Auth data for each request? What could cause such an intermittent problem? Any help or suggestions would be greatly appreciated.
source
share