ASP.NET MVC 3 simple and reliable discovery of mobile devices: use 51degrees.mobi or go to your native language?

In my ASP.NET MVC 3 web application, I redefine the view name in a custom view engine to present a different view optimized for non-tablet mobile devices.

All I want to accomplish for this redefinition is the exact value for Request.Browser.IsMobileDevice and the deviceโ€™s native screen width.

51degrees.mobi feels very difficult and confusing for this simple use case. Perhaps this is just my disappointment in trying to get through all the examples and documentation on the 51degrees website to get answers to what seem like simple questions for easy implementation.

Missing 51degrees, I get the values โ€‹โ€‹for Request.Browser.IsMobileDevice and Request.Browser.ScreenPixelsWidth . I noticed that for desktop browsers the width is always 640, while Request.Browser.Capabilities["51Degrees.mobi"] contains the value "Unknown" for ScreenPixelsWidth . I think the Unknown value is more accurate given the nature of the server-side implementation.

My main question is: do I really need 51degrees for my simple requirements?

If I do not use 51degrees, are there some concrete examples of browsers that I cannot correctly determine IsMobileDevice and screen width? For example, the built-in .NET Request.Browser.IsMobile and ScreenPixelsWidth values โ€‹โ€‹will be inaccurate or missing for the new iPad when it appears, or for the latest version of the Android browser? About 65% of mobile users get my site, many of the lame feature phones with browsers like UP.Browser, so getting mobile right is a bit important.

If I use 51degrees, do I always need to go to Request.Browser.Capabilities ["51Degrees.mobi"]? Or does 51degrees override / update the Request.Browser.IsMobileDevice value to synchronize with the browser rating? Obviously, this does not override Request.Browser.ScreenPixelsWidth.

I am open to the answers "you are doing it wrong, here is the best way" if they do not imply MVC 4 or include paid solutions such as WURFL.

+6
source share
1 answer

This FAQ explains which Request.Browser properties are overridden by 51Degrees.mobi.

There are very few cases where you should always access the 51Degrees.mobi key. If the property has been overridden by access, as usual. If the property is not overridden or not covered by HttpBrowserCapabilities, you must use the property name. For instance:

var isTablet = Request.Browser ["IsTablet"];

See the link for a list of available properties.

As this should redefine ScreenPixelsWidth, I would be interested to know more about your test environment. Since .NET requires the value to be numeric, if 51Degrees.mobi cannot determine the size (Unknown), then the value will not be overridden.

Thank you for considering 51Degrees.mobi.

+4
source

Source: https://habr.com/ru/post/910729/


All Articles