How do you check if the user browsing my website is using an iPhone, and then redirect the user to another URL?
+4
A:
Like this:
if(Request.UserAgent.IndexOf("iPhone") > 0)
Response.Redirect("~/iPhone/");
The iPhone's user-agent is
Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3
SLaks
2010-03-25 14:22:45
arg beat me to it lol. +1
KP
2010-03-25 14:24:04
Why iPhone > 0? Isn't it iPhone = true?
Fogh
2010-03-25 14:27:26
@Fogh: `IndexOf` returns the index of the string. You could also write `if (Request.UserAgent.Contains("iPhone")`.
SLaks
2010-03-25 14:29:02
Oh ofcause, thanks!
Fogh
2010-03-25 14:30:56
A:
Check the Request.UserAgent
variable for the string iPhone
. The entire string would look something like this:
HTTP_USER_AGENT=Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en)
AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1C25 Safari/419.3
klausbyskov
2010-03-25 14:24:41