EDIT Since debugging updates
According to the .net cookie documentation:
After you add a cookie by using the HttpResponse.Cookies collection, the cookie is immediately available in the HttpRequest.Cookies collection, even if the response has not been sent to the client.
My original observation were that my cookies appeared to be out of sync. After Receiving IUserIdentity, I would set an authentication cookie like so:
HttpContext.Current.Response
.RemoveCookie(FormsAuthentication.FormsCookieName);
HttpContext.Current.Request
.RemoveCookie(FormsAuthentication.FormsCookieName);
var authCookie = FormsAuthenticationExtensions.GetPersistentAuthCookie(
FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket), ticket.Expiration)
HttpContext.Current.Response.Cookies.Set(authCookie);
First I noticed that to values for the cookies we're not the same, after inspecting the same cookie in the watch window I noticed the value for the same cookie wasn't even the same:
I walked the code, and noticed that a duplicate cookie value was being set during a statement which didn't execute code. (e.g when stepping into an unrelated function the cookie now the duplicate cookie appeared in the Request and Response Cookies)
I proceeded to update all references to the cookie name in the code to help help verify what could be causing this (VM-AT-89001) => (VM-PAT-89001):
<authentication mode="Forms">
<forms cookieless="UseUri" name="VM-PAT-89001" requireSSL="true" slidingExpiration="true" timeout="1" />
</authentication>
I cleared all existing cookies, deleted the Temporary ASP.NET Files
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files
Did an IISReset and Reset my computer. When walking the code again, still the OLD cookie name was being added to the request and response.
The configurations of the cookies are different but they have the same expiration date. e.g only 1 is HTTP Only.
NOTE I've search the entire organization code base in github and there is no reference in the code to the Old Token.
They fact that this behavior happens at different points in the code depending on which controller method I call, makes me think that this is happening on a seperate thread.
Since there is no reference to the Cookie name it makes me think IIS is modifying the cookie, but this is even more perplexing because I didn't think IIS had access to the HttpContext.Current, because I can see the cookie while still debugging and not After.
How can a cookie be added to a response, when there is no reference to the cookie name in the code, and it occurs during an No-Op statement in debugger?
EDIT I've removed all filters and modules from the application (Except for adding default json formatters), and I navigate to a page that doesn't exist, and still the old token is added to the request
How can this occur?

