asp.net mvc - Removing one of two duplicate-key ASPXAUTH cookies. Code works, but why? -


my question how remove aspxauth cookie specific domain when have 2 aspxauth cookies active site.

the setup:

i have 2 sites: usermanagement.domain.com , shop.domain.com

on user "usermanagement" site, administrators can impersonate users exist on "shop".

when logging in "usermanagement", aspxauth cookie created usermanagement.domain.com site. when impersonating user, aspxauth cookie created .domain.com domain. (which practically authenticates user on shop.domain.com well. works way because usermanagement.domain.com cannot create cookie shop.domain.com - therefore, shared .domain.com used instead.)

this means when administrator impersonates user, following 2 aspxauth cookies exist:

  • .aspxauth (domain: usermanagement.domain.com)
  • .aspxauth (domain: domain.com)

now, when administrator stops impersonating user, want remove ".domain.com" aspxauth cookie. following code accomplishes goal:

if (request.cookies.allkeys.contains(".aspxauth")) {     var domain = _configurationservice.getb2bsettings().backofficeandimpersonationdomain;     var impersonationcookie = new httpcookie(".aspxauth")     {         domain = domain,         expires = datetime.now.adddays(-1)     };     response.cookies.add(impersonationcookie); }  return redirect(homeurl); 

and have sort "it works, don't know why"-moment. above code removes .aspxauth ".domain.com" domain. other aspxauth cookie gets live.

my question is: how work?

the new cookie created in above excerpt not merged request cookies @ point. in fact, before redirect performed, request contains 3 .aspxauth cookies (two original aspxauth cookies, , newly added cookie).

(on side note: know setup not ideal or intuitive, due scope of task, i'm not going change domain/site setup @ moment. i'm curious how above code works.)


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -