UnauthorizedAccessException after using LogonUser

I am redefining Application_AuthenticateRequestto replace a Windows authenticated user with another user that I programmatically get on a call LogonUser. When I assign the resulting WindowsPrinciple Context.User , I get the following exception. I do not get this exception on my development machine (everything works fine), only on my QA machine. Both machines are Windows Server 2008 R2. There is something else on the QA machine, but I don't know what it is.

Here is a complete description of what I'm trying to accomplish.

    [UnauthorizedAccessException: Attempted to perform an unauthorized operation.]
   System.Security.Principal.WindowsIdentity.get_AuthenticationType() +317
   System.Web.Hosting.IIS7WorkerRequest.SetPrincipal(IPrincipal user, IntPtr pManagedPrincipal) +106
   System.Web.HttpContext.SetPrincipalNoDemand(IPrincipal principal, Boolean needToSetNativePrincipal) +9022044
   System.Web.HttpContext.SetPrincipalNoDemand(IPrincipal principal) +6
   System.Web.HttpContext.set_User(IPrincipal value) +36
   MyProj.MvcApplication.OverrideLoginUser() in C:\Data\Project\MyProj\Global.asax.cs:317
   MyProj.MvcApplication.Application_AuthenticateRequest(Object sender, EventArgs e) in C:\Data\Project\MyProj\Global.asax.cs:305
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +148
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

Update

QA, "ApplicationPoolIdentity" "LocalSystem". Dev ApplicationPoolIdentity, ? ?

2

. "" . , , - LocalSystem. ( ). . .

+5
1

Ok. 5 , . Identity.AuthenticationType, Context.User. Dev. , , - dev- Context.User, QA. , , , AuthenticationType WindowsIdentity. , , ! :

// Construct a WindowsIdentity object using the input account token 
// and the specified authentication type.
var foo = new WindowsIdentity(logonToken, "WindowsAuthentication");

! !

+3

All Articles