c# - WindowsIdentity.Impersonate in ASP.NET randomly "Invalid token for impersonation - it cannot be duplicated" -



c# - WindowsIdentity.Impersonate in ASP.NET randomly "Invalid token for impersonation - it cannot be duplicated" -

i have asp.net app requires users sign in domain accounts using basic authentication. user can create selection, press button.

at point after pressing button code: windowsidentity.impersonate(useridentity.token). useridentity of type windowsidentity, , set (windowsidentity)user.identity.

useridentity stored session variable, , think that's because, after button pressed, page containing code called via ajax.

when nail code, works 2/3 of time, 1/3 of time, exception: invalid token impersonation - cannot duplicated. think biggest head scratcher me why work not other times? on sessions, works several times before failing. on others, fails right away.

here's stack trace:

at system.security.principal.windowsidentity.createfromtoken(intptr usertoken)

at system.security.principal.windowsidentity..ctor(intptr usertoken, string authtype, int32 isauthenticated)

at system.security.principal.windowsidentity.impersonate(intptr usertoken)

at resource_booker.bll.reservationagent.submitreservationrequest(reservation reservation, patron patron) in c:\dev\roomres\resource booker\bll\reservationagent.cs:line 101

at resource_booker.reserve.reserve_click(object sender, eventargs e) in c:\dev\roomres\resource booker\reserve.aspx.cs:line 474

at system.eventhandler.invoke(object sender, eventargs e)

at system.web.ui.webcontrols.button.raisepostbackevent(string eventargument)

at system.web.ui.page.processrequestmain(boolean includestagesbeforeasyncpoint, boolean includestagesafterasyncpoint)

here's confounding factor: cannot reproduce problem on local windows 7 x64 workstation--albeit authentication passed implicitly here since using localhost--or on windows 2003 32-bit iis 6.0 environment. happens on pretty vanilla windows 2008 r2 environment. these environments domain members.

basically seeing not security problem logon session cached iis lifetime of tcp connection, http cutting tcp connection requiring re-authentication. happen seamlessly , invisibly (handled browser) invalidate token, logon session destroyed when tcp connection ends.

i.e. benefit of @usr, works because logon session same token same, token stored in session works because happens same actual token user.identity. it's not way of avoiding security check implementation detail of security check.

you shouldn't storing identity in session - unnecessary since authenticated connection.

just utilize (windowsidentity)user.identity every single time , problem should go away.

c# asp.net ajax basic-authentication windows-identity

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -