Forum Discussion
earton_25699
Nimbostratus
Mar 21, 2009iRule for IE8
With the release of IE8 yesterday, I need to be able to automatically make users who have IE8 installed to be forced into an IE7 compatible mode. I have read some articles on Microsoft that details doing this by the use of the following commands
Is it possible to do the same thing in an iRule when a client connects to a virtual server which hosts IIS servers.
Could I use the following
HTTP::respond [content ] [noserver] [ ]+
If so, what values would I put where?
11 Replies
- The_Bhattman
Nimbostratus
There is an articular which depicts a way to insert the code ito page to inform a client to upgrade. I suppose the same can be done to insert a piece of code based on it detecting IE8
Click here to see if this can help you come up with a game plan
Hope this helps
CB - Looks to me like the above config is for IIS and is just creating a custom response header for all requests. If you want to add this to all requests, regardless of the browser, it would be as simple as this:
when HTTP_RESPONSE { HTTP::header insert "X-UA-Compatible" "IE=EmulateIE7" }
If you want to only do this for IE8 browsers, you'll need to add a HTTP_REQUEST event and look at the value of [HTTP::header User-Agent] and if that matches IE8 (I don't have that value handy), then you could set a value that is read in the HTTP_RESPONSE to determine whether the header is added.
You also, might want to check if the header already exists in the response and only add it if it's not there already.when HTTP_RESPONSE { if { ! [HTTP::header exists "X-UA-Compatible"] } { HTTP::header insert "X-UA-Compatible" "IE=EmulateIE7" } }
But, based on the config above, it's globally setting the header for all responses to the above iRule should work for you.
Let us know if this works out for you.
-Joe - earton_25699
Nimbostratus
Thanks for replies. Will let you know how it goes - Doh! Don't write iRules for a few weeks and see what happens. Thanks for the catch hoolio!
*Reply above has been corrected.
-Joe - bilsch_10068
Nimbostratus
I have been working on a rule to do this but it does not quite work. Any ideas?
reference sites
1) http://msdn.microsoft.com/en-us/library/cc817582.aspx
2) http://msdn.microsoft.com/en-us/library/cc817570.aspx
rule IE8Fix {
when RULE_INIT {
set ::IE8Resp 0
}
when HTTP_REQUEST {
if { [regexp {"MSIE ([0-9]{1,}[\.0-9]{0,})"} [HTTP::header User-Agent] origUA UAVer ] } {
switch $UAVer {
"8.0" {
set ::IE8Resp 1
log "[IP::client_addr]:[TCP::client_port] IE 8 detected"
}
"7.0" {
set ::IE8Resp 0
log "[IP::client_addr]:[TCP::client_port] IE 7 detected"
}
default {
log "[IP::client_addr]:[TCP::client_port] IE $UAVer detected"
}
}
}
}
when HTTP_RESPONSE {
if { $::IE8Resp } {
todo, make sure the header insert format is right
log "[IP::client_addr]:[TCP::client_port] inserting header"
HTTP::header insert "X-UA-Compatible" "IE=EmulateIE7"
}
}
}
I was trying to make it only trigger when the browser was IE8...
Is my impression that the entire rule ( eg, http_request, http_response, rule_init ) execute on a per-request/response pair or is that not the case? - hoolio
Cirrostratus
A global variable will be accessible and changeable across all TCP connections. You'd want to use a local variable so that it's only accessible across a single TCP connection.
With that said, I don't think there is any reason to check whether to insert the response header or not. Just insert it in every response and non-IE8 browsers will ignore it.
If you do want to check the User-Agent header before setting the custom X-UA-Compatible header in the response, you could do something like this. Note, as Joe always says, you should use string operations instead of regexes whenever possible to save CPU cycles/memory.when HTTP_REQUEST { Check if User-Agent header is IE 8 if { [HTTP::header User-Agent] contains "MSIE 8" } { set IE8Resp 1 } else { set IE8Resp 0 } } when HTTP_RESPONSE { if { $IE8Resp } { log "[IP::client_addr]:[TCP::client_port] inserting header" HTTP::header insert "X-UA-Compatible" "IE=EmulateIE7" } }
Aaron - bilsch_10068
Nimbostratus
Yea that makes sense on the regexp - good point. Thanks! Posted By hoolio on 03/25/2009 9:14 AM
...Note, as Joe always says, you should use string operations instead of regexes whenever possible to save CPU cycles/memory.
Amen brother!
-Joe- The_Bhattman
Nimbostratus
This should be uploaded in the samples - hoolio
Cirrostratus
Hey cmbhatt, it's a wiki, so you could add it too :D. Here you go:
http://devcentral.f5.com/wiki/default.aspx/iRules/Emulate_IE7_header_insertion_in_response_for_IE8.html (Click here)
Aaron
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