Forum Discussion
William_Wright_
Nimbostratus
Dec 19, 2005Basic cookie session iRule
I need to create a basic iRule that keeps persistence based on JSESSION and load balances accordingly otherwise. I have tried all the standard persistence methods but it always goes back to defaulting to source IP. I have found quite a few example iRules but most of them get very involved. Can someone get me an example of how a basic iRule for session persistence using JSESSION would be??
Thank you
9 Replies
- Colin_Walker_12Historic F5 AccountHere's a simplified version of the rule given in this thread Click here
when HTTP_REQUEST { set jsess [findstr [HTTP::uri] "jsessionid" 11 ";"] if { $jsess != "" } { persist uie $jsess } }
This should enable persistence based on the jsessionid in the uri, assuming it matches the format the findstr command in this example is looking for ( jsessionid=x...y; ).
-Colin - William_Wright_
Nimbostratus
I did an ethereal trace and found that the JSESSIONID. here is what it looks like:
Set-Cookie: JSESSIONID=78B127CEBC4D19E5FDA6F69259667964;
Also what does the number designate in this line: "jsessionid" 11 " ? - JRahm
Admin
That will strip jsessionid= (11 characters) out of the string so that only the session id is persisted on. - William_Wright_
Nimbostratus
I also need to put an else statement that uses a pool if the JSESSIONID does not exist. Where would I put that??? - Colin_Walker_12Historic F5 AccountThis should be pretty straight forward. There are literally hundreds of examples of this sort of thing in the forums if you look around a little. It's always best to use the search function or even just browse around to see if there are answers to the questions you have, as many people are working on or have worked on similar rules that can help each other with their experience.
In any event, it would look like this:when HTTP_REQUEST { set jsess [findstr [HTTP::uri] "jsessionid" 11 ";"] if { $jsess != "" } { persist uie $jsess } else { pool yourPool } }
hth,
-Colin - William_Wright_
Nimbostratus
How can I log what the cookie name is or the cookie contents?? - Colin_Walker_12Historic F5 AccountYou might also want to check out askf5.com for some iRules documentation on the different commands like HTTP::cookie.
Check it out here: Click here - http://tech.f5.com/home/bigip-next/manuals/bigip9_2/bigip9_2config/BIG_IP9_2ConfigGuide-14-1.htmlwp1200312
Note: that link points to the 9.2 documentation...earlier versions are available.
-Colin - William_Wright_
Nimbostratus
I am getting inconsistant results. Sometimes the persistence works and sometimes it does not. After using some ethereal traces I found that even using an iRule to do JSESSIONID persistence it also uses source port. Is there anyway to write a rule that will only look at the JSESSIONID and not the source port?? - unRuleY_95363Historic F5 AccountDo you mean the source port embedded in the JSESSIONID?
UIE persistence uses whatever data you give it, so parsing different parts of the JSESSIONID are certainly possible.
I haven't looked at a JSESSIONID recently, so I'm not sure what the format looks like now.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects