As hoolio mentions, you can delete entries using the “session delete” or “persist delete” commands, but entries will expire out of the table with the idle timeout expiry. In your code, the timeout is set to 1800 seconds, or 30 minutes.
That should happen by default unless your rule specifies otherwise. if the timeout is set to match the cookie timeout, or (the intended application idle timeout if using session cookies).
There is actually a slightly more efficient example in the codeshare here (uses a bit simpler approach for the response):
Click here
(Note that for this version, timeouts are controlled by the persistence profile via which it is applied to the virtual server.)
I’d change your request logic also so the logic after the redirect only runs if the redirect doesn’t.
You also mentioned in email that this solution isn't working across http & https virtuals, and that requires a specific session command parameter "any virtual"
I’d recommend using something more along these lines (although you might have to adjust what part of jsessionid value you are using):
when HTTP_REQUEST {
if { [active_members MyPool] == 0 } {
HTTP::redirect "http://[HTTP::header "X-Forwarded-Host"]/myUri.html"
} else {
if { [HTTP::header exists "X-Forwarded-Host"] } {
HTTP::header replace "Host" [HTTP::header "X-Forwarded-Host"]
}
if { [HTTP::cookie exists "JSessionID"] } {
log "used Cookie, value is [HTTP::cookie "JSessionID"]"
persist uie {[HTTP::cookie "JSessionID"] any virtual}
} else {
set jsess [findstr [HTTP::uri] "JSessionID" 11 ";"]
if { $jsess != "" } {
persist uie {$jsess any virtual}
}
}
}
}
when HTTP_RESPONSE {
if { [HTTP::cookie exists "JSessionID"] } {
persist add uie {[HTTP::cookie "JSessionID"] any virtual}
}
}
HTH
/deb