The site is running on my local IIS 6.1. I Would like to add some features to pull information from our AD. My AD code works on many other projects and on my dev server. Her
This snippet shows how LogonUserIdentity
is set (using reflector)
if ((this._wr is IIS7WorkerRequest) && (((this._context.NotificationContext.CurrentNotification == RequestNotification.AuthenticateRequest) && !this._context.NotificationContext.IsPostNotification) || (this._context.NotificationContext.CurrentNotification < RequestNotification.AuthenticateRequest)))
{
throw new InvalidOperationException(SR.GetString("Invalid_before_authentication"));
}
IntPtr userToken = this._wr.GetUserToken();
if (userToken != IntPtr.Zero)
{
string serverVariable = this._wr.GetServerVariable("LOGON_USER");
string str2 = this._wr.GetServerVariable("AUTH_TYPE");
bool isAuthenticated = !string.IsNullOrEmpty(serverVariable) || (!string.IsNullOrEmpty(str2) && !StringUtil.EqualsIgnoreCase(str2, "basic"));
this._logonUserIdentity = CreateWindowsIdentityWithAssert(userToken, (str2 == null) ? "" : str2, WindowsAccountType.Normal, isAuthenticated);
}
As you can see this has been changed for IIS 7.
I believe you are using Windows Authentication + Impersonation so I would go with the last one (WindowsIdentity.GetCurrent()
) which I am sure is the identity request being run with.