Answered by:
Detect Mobile and Tablet devices

Question
-
User1266403470 posted
Hi Friends...Can anyone of you help me in my below query....
In my web application I use the following code to detect any mobile devices and redirect to the mobile version of site.
string strUserAgent = Request.UserAgent.ToString().ToLower();
if (strUserAgent != null)
{
if ((Request.Browser.IsMobileDevice == true ||
strUserAgent.Contains("iphone") || strUserAgent.Contains("ipod") ||
strUserAgent.Contains("symbian") || strUserAgent.Contains("android") ||
strUserAgent.Contains("windows ce") || strUserAgent.Contains("blackberry") ||
strUserAgent.Contains("palm") || (strUserAgent.Contains("mobile") && !strUserAgent.Contains("ipad")) ||
strUserAgent.Contains("opera mini")) && (Session["VFS"] == null))
{
string fullsiteurl = Request.RawUrl.ToString();
Response.Redirect("http://m.huggies.com");
}
}Now, I wanted to do a check for tablet devices and redirect to desktop version of site if it is a tablet device. As of now it is done in the above code but only for iPad.
I need to add conditions for the following tablet devices and all others too that are not listed. Can anyone help me?
Samsung Galaxy Tab 10.1 GT-P7510
Mozilla/5.0 (Linux; U; Android 3.1; xx-xx; GT-P7510 Build/HMJ37) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13
Samsung Galaxy Tab GT-P1000
Mozilla/5.0 (Linux; U; Android 2.2; es-es; GT-P1000 Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
Samsung Galaxy Tab SC-01C for DoCoMo
Mozilla/5.0 (Linux; U; Android 2.2; ko-kr; SC-01C Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
Samsung Galaxy Tab SCH-I800
Mozilla/5.0 (Linux; U; Android 2.2; en-us; SCH-I800 Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
Samsung Galaxy Tab SGH-T849
Mozilla/5.0 (Linux; U; Android 2.2; en-us; SGH-T849 Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
Samsung Galaxy Tab SHW-M180L
Mozilla/5.0 (Linux; U; Android 2.2; xx-xx; SHW-M180L Build/FROYO) AppleWebKit/525.10 (KHTML, like Gecko) Version/3.0.4 Mobile Safari/523.12.2
Samsung Galaxy Tab SHW-M180S
Mozilla/5.0 (Linux; U; Android 2.2; xx-xx; SHW-M180S Build/FROYO) AppleWebKit/525.10 (KHTML, like Gecko) Version/3.0.4 Mobile Safari/523.12.2
Samsung Galaxy Tab SPH-P100
Mozilla/5.0 (Linux; U; Android 2.2; 0-; SPH-P100 Build/FROYO) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
Thursday, February 9, 2012 6:09 PM
Answers
All replies
-
User-58016157 posted
You could use the Request.Browser.ScreenPixelsWidth to determine if it meets a certain size applicable to view the desktop version. Recommend you check what sort of sizes they use.
Friday, February 10, 2012 6:40 AM -
-
User1266403470 posted
Thanks guys for the replies. I hardcoded for the lists that I had mentioned.
@Roopesh Reddy. I tested using the solution that you have given and it works like a charm :)
Friday, December 7, 2012 4:22 PM