title: ASP.NET Impersonate in .NETFramework 2 VS .NETFrameWork 4
body: <p>We have an ASP.NET Site in .NetFramework 2 (with App Pool 2 Classic in IIS 7.5), We use mixed Authentication with <code>Basic Authenticate</code> and <code>Form Authenticate</code>.</p>
  
  <p>The Configuration in IIS is: </p>
  
  <p><img src="https://i.stack.imgur.com/t0pD5.jpg" alt="enter image description here"></p>
  
  <p>And have specific user in Anonymous Authentication named: <code>Guest</code>.</p>
  
  <p>When The user Login with another username like <code>Admin</code> we use impersonate:</p>
  
  <pre><code>string Token = GetSpecificTokenOfCurrentUser();
  System.Security.Principal.WindowsIdentity WinUser = (WindowsIdentity) HttpContext.Current.Application["User_"+Token];
  WinUser.Impersonate();
  </code></pre>
  
  <p>So every thing is perfect until we upgrade website to .NetFramework 4 and add a lot of features in .NET 4 to website, and we figured we have a new Problem.</p>
  
  <p>The problem is the user login with <code>Admin</code> And open some pages (3-4) all together in same time, like quickly opened in new tab, the User Not impersonated in some cases. Like the first page impersonated correctly to <code>Admin</code> but another pages not impersonated and still have <code>Guest</code> User.</p>
  
  <p>This is so weird, we don't have any changes in Authentication Part. the changes is we upgrade to .NetFrameWork 4 and App Pool is .NetFrameWork 4 - Classic.</p>
  
  <p>We have a test in .Net 2 Version Of Website. every thing is OK, but we change the App Pool to .NetFrameWork 4 and the problem was shown.</p>
  
  <p>So The question is what changes happened in .NetFramework 4 App Pool to Impersonate?</p>
  
  <p>Is there any thing we missed? any suggestion?</p>