Forum Discussion
ASP stickiness with multiple cookies
Hi, i know that there's is already a codeshare example for this kind of stickiness but i need an extension and i don't know how to set up the rule.
I set up the following IRule:
when HTTP_REQUEST {
set SessionId [HTTP::cookie ASP.NET_SessionId]
log local0. "Request SessionId is: $SessionId"
if { $SessionId != "" } { persist uie $SessionId }
}
when HTTP_RESPONSE {
set SessionId [findstr [HTTP::header Set-Cookie] "ASP.NET_SessionId" 18 24]
log local0. "Response SessionId is: $SessionId"
if { $SessionId != "" }{ persist add uie $SessionId }
}
which works fine for the request but not the response. the problem is that the server sends 4 'Set-Cookie' statements and the 'ASP.NET_SessionId' is the first one in the list.
this is what the server responds:
Set-Cookie: ASP.NET_SessionId=edfozx45o40stpfgnbtue045; path=/; HttpOnly
Set-Cookie: EPowerV4Users=carrefourvoyagesb2b=13_user; path=/
Set-Cookie: EPowerV4UsersCorporates=carrefourvoyagesb2b=agencyantibes; path=/
Set-Cookie: VisitorID=1703234c-e2be-45a4-a9c3-29183aa09fde; expires=Fri, 23-Nov-2012 07:55:38 GMT; path=/
X-Powered-By: ASP.NET
i found in the wiki the statement forn http:header:
'Note that the command will operate on the value of the last header if there are multiple headers with the same name'
So i would need now an expension of the rule to look at all 'Set-Cookie' headers and apply stickieness
based on the asp session id.
I tried to put together bits and pieces from different other rules but it seems that my skills are not good enough to get it working.
Can someone please help me.
- nitass
Employee
there is HTTP::header values which will return value of all the header. so, you can go through each of them. can you try? - nitass
Employee
e.g.[root@ve1023:Active] config b virtual bar list virtual bar { snat automap pool foo destination 172.28.19.79:80 ip protocol 6 rules myrule profiles { http {} tcp {} } } [root@ve1023:Active] config b rule myrule list rule myrule { when HTTP_RESPONSE { foreach acookie [HTTP::header values "Set-Cookie"] { log local0. "$acookie" } } } [root@ve1023:Active] config curl -I http://172.28.19.79 HTTP/1.1 200 OK Date: Wed, 23 Nov 2011 14:57:09 GMT Server: Apache/2.2.3 (CentOS) Last-Modified: Fri, 11 Nov 2011 14:48:14 GMT ETag: "4183e4-3e-9c564780" Accept-Ranges: bytes Content-Length: 62 Set-Cookie: ASP.NET_SessionId=edfozx45o40stpfgnbtue045; path=/; HttpOnly Set-Cookie: EPowerV4Users=carrefourvoyagesb2b=13_user; path=/ Set-Cookie: EPowerV4UsersCorporates=carrefourvoyagesb2b=agencyantibes; path=/ Set-Cookie: VisitorID=1703234c-e2be-45a4-a9c3-29183aa09fde; expires=Fri, 23-Nov-2012 07:55:38 GMT; path=/ Connection: close Content-Type: text/html; charset=UTF-8 [root@ve1023:Active] config Nov 23 06:56:55 local/tmm info tmm[23027]: Rule myrule : ASP.NET_SessionId=edfozx45o40stpfgnbtue045; path=/; HttpOnly Nov 23 06:56:55 local/tmm info tmm[23027]: Rule myrule : EPowerV4Users=carrefourvoyagesb2b=13_user; path=/ Nov 23 06:56:55 local/tmm info tmm[23027]: Rule myrule : EPowerV4UsersCorporates=carrefourvoyagesb2b=agencyantibes; path=/ Nov 23 06:56:55 local/tmm info tmm[23027]: Rule myrule : VisitorID=1703234c-e2be-45a4-a9c3-29183aa09fde; expires=Fri, 23-Nov-2012 07:55:38 GMT; path=
- quickref_74249
Nimbostratus
hi Nitass, - nitass
Employee
So i would need now an expension of the rule to look at all 'Set-Cookie' headers and apply stickieness - nitass
Employee
can you try this? anyway, sorry i have not yet tested it.[root@ve1023:Active] config b rule myrule list rule myrule { when HTTP_REQUEST { set SessionId [HTTP::cookie ASP.NET_SessionId] log local0. "Request SessionId is: $SessionId" if {$SessionId != ""} {persist uie $SessionId} } when HTTP_RESPONSE { foreach acookie [HTTP::header values "Set-Cookie"] { set SessionId [findstr $acookie "ASP.NET_SessionId" 18 24] log local0. "Response SessionId is: $SessionId" if {$SessionId != ""}{persist add uie $SessionId} } } }
- quickref_74249
Nimbostratus
that one did the trick. thank you very much for your help. i won't say that i wasted half of the day as i learned a lot about IRules but without your help i think i would been lost for some more time. - hoolio
Cirrostratus
HTTP::cookie ASP.NET_SessionId will return the value for the (last) ASP.NET_SessionId cookie, regardless of how many other cookies are set in the response. So you shouldn't need to parse the Set-Cookie headers anyhow.when HTTP_REQUEST { set SessionId [HTTP::cookie ASP.NET_SessionId] log local0. "[IP::client_addr]:[TCP::client_port]: Request SessionId is: $SessionId" if { $SessionId != "" } { persist uie $SessionId 3600 } } when LB_SELECTED { log local0. "[IP::client_addr]:[TCP::client_port]: Selected [LB::server]" } when LB_FAILED { log local0. "[IP::client_addr]:[TCP::client_port]: Failed [LB::server]" } when SERVER_CONNECTED { log local0. "[IP::client_addr]:[TCP::client_port]: Connected [IP::server_addr]:[TCP::server_port]" } when HTTP_RESPONSE { set SessionId [findstr [HTTP::cookie "ASP.NET_SessionId"] 18 24] log local0. "[IP::client_addr]:[TCP::client_port]: "Response SessionId is: $SessionId from Set-Cookies: [HTTP::header values Set-Cookie]" if { $SessionId != "" }{ persist add uie $SessionId 3600 log local0. "[IP::client_addr]:[TCP::client_port]: Persist record [persist lookup uie $SessionId]" } }
- nitass
Employee
Aaron,[root@ve1023:Active] config b virtual bar list virtual bar { snat automap pool foo destination 172.28.19.79:80 ip protocol 6 rules myrule profiles { http {} tcp {} } } [root@ve1023:Active] config b rule myrule list rule myrule { when HTTP_REQUEST { set SessionId [HTTP::cookie ASP.NET_SessionId] log local0. "[IP::client_addr]:[TCP::client_port]: Request SessionId is: $SessionId" if { $SessionId != "" } { persist uie $SessionId 3600 } } when LB_SELECTED { log local0. "[IP::client_addr]:[TCP::client_port]: Selected [LB::server]" } when LB_FAILED { log local0. "[IP::client_addr]:[TCP::client_port]: Failed [LB::server]" } when SERVER_CONNECTED { log local0. "[IP::client_addr]:[TCP::client_port]: Connected [IP::server_addr]:[TCP::server_port]" } when HTTP_RESPONSE { set SessionId [findstr [HTTP::header Set-Cookie] "ASP.NET_SessionId" 18 24] set SessionId [HTTP::cookie "ASP.NET_SessionId"] log local0. "[IP::client_addr]:[TCP::client_port]: Response SessionId is: $SessionId from Set-Cookies: [HTTP::header values Set-Cookie]" if { $SessionId != "" }{ persist add uie $SessionId 3600 log local0. "[IP::client_addr]:[TCP::client_port]: Persist record [persist lookup uie $SessionId]" } } } [root@ve1023:Active] config curl -I http://172.28.19.79 HTTP/1.1 200 OK Date: Wed, 23 Nov 2011 22:04:39 GMT Server: Apache/2.2.3 (CentOS) Last-Modified: Fri, 11 Nov 2011 14:48:14 GMT ETag: "4183e4-3e-9c564780" Accept-Ranges: bytes Content-Length: 62 Set-Cookie: ASP.NET_SessionId=edfozx45o40stpfgnbtue045; path=/; HttpOnly Set-Cookie: EPowerV4Users=carrefourvoyagesb2b=13_user; path=/ Set-Cookie: EPowerV4UsersCorporates=carrefourvoyagesb2b=agencyantibes; path=/ Set-Cookie: VisitorID=1703234c-e2be-45a4-a9c3-29183aa09fde; expires=Fri, 23-Nov-2012 07:55:38 GMT; path=/ Connection: close Content-Type: text/html; charset=UTF-8 [root@ve1023:Active] config Nov 23 14:04:25 local/tmm info tmm[23027]: Rule myrule : 172.28.19.80:56914: Request SessionId is: Nov 23 14:04:25 local/tmm info tmm[23027]: Rule myrule : 172.28.19.80:56914: Selected foo 200.200.200.101 80 Nov 23 14:04:25 local/tmm info tmm[23027]: Rule myrule : 172.28.19.80:56914: Connected 200.200.200.101:80 Nov 23 14:04:25 local/tmm info tmm[23027]: Rule myrule : 172.28.19.80:56914: Response SessionId is: edfozx45o40stpfgnbtue045 from Set-Cookies: {ASP.NET_SessionId=edfozx45o40stpfgnbtue045; path=/; HttpOnly} {EPowerV4Users=carrefourvoyagesb2b=13_user; path=/} {EPowerV4UsersCorporates=carrefourvoyagesb2b=agencyantibes; path=/} {VisitorID=1703234c-e2be-45a4-a9c3-29183aa09fde; expires=Fri, 23-Nov-2012 07:55:38 GMT; path=/} Nov 23 14:04:25 local/tmm info tmm[23027]: Rule myrule : 172.28.19.80:56914: Persist record foo 200.200.200.101 80
- hoolio
Cirrostratus
Yep, that should have been [HTTP::cookie "ASP.NET_SessionId"] in HTTP_RESPONSE.
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com