Forum Discussion
Irule not working for Cookie Persistence
Hi Team,
We have one application and can be accessed via F5 successfully and we are using cookie persistence for that. Now we are trying to access through Mobile devices. Since there is no cookie for mobile, I wrote a Irule for this.
I created a universal persistence for this Virtual server and applied following Irule for this,.Now Mobile traffic is working fine but I am not sure how to add insert cookie for my Browser traffic (else condition in my loop). I tried different option and none of them are working. Can anybody help me on this
when HTTP_REQUEST {
log "MA Testing : Requested from IP [IP::client_addr]"
set cid [findstr [HTTP::uri] "contextId" 10 "&"] if { $cid != "" } {
log "\MA Testing : ContextId found. Persist based on contextid : $cid"
persist uie $cid
log "MA Testing: Pool member [LB::server name] was selected"
} else
log "\MA Testing : No context id found. So persist based on Session id in the cookie"
persist uie cookie
log "MA Testing: Pool member [LB::server name] was selected"
} }
1 Reply
Hi Akhilesh,
the command
does not set/read any kind of HTTP cookies, its more or less just tracking your session persistence using the static plain-text value "[persist uie cookie]
".cookieTo understand the
behavior, you have to read the command like[persist uie]
, where the string can be any kind of information the user would provide while requesting information. It could be a source IP, it could be an URI, it could be an HTTP-Header or HTTP-Cookie value the user is providing on each single request. Well, in your specific case, you're not using any provided data, instead your using the fixed value of "cookie" for every client causing to team every session to the same pool_member...[persist uie UNIVERSAL_TXT_STRING_TO_TRACK]To track your users based on a HTTP-Cookie value using
your need to monitor the[persist uie]
for the desired HTTP-Cookie value. If the value is present, thenHTTP_REQUEST
the session. If the user is not providing the desired cookie, then perform a regular load-balacing decission (e.g. Round-Robin) and monitor the[persist uie $cookie_value]
if the server sets the cookie. As soon the server is setting the Cookie, issue aHTTP_RESPONSE
to team the cookie value to the current pool_member selection. The very next REQUEST of the user would then provide the[persist add uie $cookie_value]
which can be used to$cookie_value
the request to the last pool_member selection.[persist uie $cookie_value]Alternativly you could also use the
command, to let the F5 insert an auto-generated cookie used exclusivly for persisting the session. Its a much easier syntax and does not require any well known application cookies to be in place. In addition to that its completely stateless and therefor doesn't consume session table memory to store the persitence information...[persist cookie insert MY_LB_COOKIE_NAME]Cheers, Kai
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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