Forum Discussion
kraysco_322584
Nimbostratus
Jun 02, 2017iRule - command is not valid in the current event context - cookie management
I am attempting to write an iRule that checks a cookie on HTTP_REQUEST and then writes a cookie on HTTP_RESPONSE in order to control the display of a banner message:
when CLIENT_ACCEPTED {
set ckname NotificationDone
set ckvalue 1
set ckdomain .[HTTP::host]
}
when RULE_INIT {
set static::notification_page {
... HTML Notification Page - code omitted ... }
}
when HTTP_REQUEST {
if { (not [HTTP::cookie exists NotificationDone]) } {
HTTP::respond 200 content [subst $static::notification_page] Mime-Type "text/html"
}
}
when HTTP_RESPONSE {
if { (not [HTTP::cookie exists NotificationDone]) } {
HTTP::cookie insert name $ckname value $ckvalue path / domain $ckdomain
HTTP::cookie expires $ckname 120
}
}
When I run this code I get: "[command is not valid in the current event context(CLIENT_ACCEPTED)][HTTP::host]" I also get an similar error in the HTTP_RESPONSE when I attempt to set the cookie.
I've seen a number of examples that use this same pattern so I'm not sure what I am missing. Any help would be greatly appreciated.
Kevin
- cjunior
Nacreous
The command is on wrong layer place.
when RULE_INIT { set static::notification_page { ... HTML Notification Page - code omitted ... } } when HTTP_REQUEST { set ckname NotificationDone set ckvalue 1 set ckdomain ".[HTTP::host]" if { (not [HTTP::cookie exists $ckname]) } { HTTP::respond 200 content [subst $static::notification_page] Mime-Type "text/html" } } when HTTP_RESPONSE { if { (not [HTTP::cookie exists $ckname]) } { HTTP::cookie insert name $ckname value $ckvalue path / domain $ckdomain HTTP::cookie expires $ckname 120 } }
Regards.
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