Wondering if I am doing something wrong or if there is another solution altogether.
Here is some testing code I just wrote out:
HttpBrowserCapabilitiesBase browser = this.Context.Request.Browser;
var width = browser.ScreenPixelsWidth;
var height = browser.ScreenPixelsHeight;
var maxheight = browser.MaximumRenderedPageSize;
bool mobile = browser.IsMobileDevice;
string pageUrl = Request.Url.AbsolutePath.ToString();
if(width < 960)
{
...
}
I am testing on my development machine which of course is a desktop. My screen resolution is 1920 x 1200. However, my width and height variables are getting set to 640 and 480 respectively. I have tested this in IE and Chrome so far.
Some of these values aren't determined dynamically (like width/height). These values were originally developed when there was a handful of devices and they could build a server-side database with all the known dimensions of these devices. If you need to
know the dimensions at runtime use JavaScript in the browser.
Member
52 Points
69 Posts
Browsing device properties via HttpBrowserCapabiltiesBase are way off.
Aug 11, 2012 12:25 AM|MagianCreative|LINK
Wondering if I am doing something wrong or if there is another solution altogether.
Here is some testing code I just wrote out:
I am testing on my development machine which of course is a desktop. My screen resolution is 1920 x 1200. However, my width and height variables are getting set to 640 and 480 respectively. I have tested this in IE and Chrome so far.
All-Star
20376 Points
6505 Posts
ASPInsiders
MVP
Re: Browsing device properties via HttpBrowserCapabiltiesBase are way off.
Aug 11, 2012 09:21 AM|BrockAllen|LINK
Some of these values aren't determined dynamically (like width/height). These values were originally developed when there was a handful of devices and they could build a server-side database with all the known dimensions of these devices. If you need to know the dimensions at runtime use JavaScript in the browser.
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
Star
14065 Points
3270 Posts
Re: Browsing device properties via HttpBrowserCapabiltiesBase are way off.
Aug 20, 2012 10:29 AM|roopeshreddy|LINK
Hi,
HttpBrowserCapabilities class won't provide you accurate browser details!!!
You may need to build your own - http://roopeshreddy.wordpress.com/2012/06/24/detect-requesting-device-type-and-redirect-in-asp-net/
Otherwise, you may have to use CSS3 Media queries - http://www.css3.info/preview/media-queries/
http://www.w3.org/TR/css3-mediaqueries/
http://mobile.smashingmagazine.com/2010/07/19/how-to-use-css3-media-queries-to-create-a-mobile-version-of-your-website/
Hope it helps u...
Roopesh Reddy C
Roopesh's Space