ASP.NET Mobile Views - does not detect Firefox Mobile as mobile

I am using ASP.NET MVC5 and I present a bunch of .Mobile views in some specific scenarios.

I noticed that the Mozilla Firefox mobile app on Android does not get the .Mobile version of the rendered view, so it, like ASP.NET, does not detect that the device is mobile.

The UA string is Mozilla / 5.0 (Android; Mobile; rv: 39.0). Gecko / 39.0 Firefox / 39.0

Is there a way I can globally override mobile detection to possibly force this?

+3


source to share


1 answer


Yes you can use DisplayModeProvider

in namespace System.Web.WebPages

.

You can add your own logic in DisplayModeProvider

to determine which view should be displayed.

If you add this to your startup or application initialization:



DisplayModeProvider.Instance.Modes
.Add(new DefaultDisplayMode("Mobile")
                {
                    ContextCondition = context => {
                        var userAgent = context.GetOverriddenUserAgent();
                        return userAgent.IndexOf("Android", StringComparison.OrdinalIgnoreCase) > -1
                               && userAgent.IndexOf("Mobile", StringComparison.OrdinalIgnoreCase) > -1
                               && userAgent.IndexOf("Firefox", StringComparison.OrdinalIgnoreCase) > -1;
                    }
                });

      

This will result in the HTTP requests that have "Android"

, "Mobile"

and "Firefox"

in the User Agent string, to your views placed in Mobile.

Likewise, you can create specific overrides and views for specific devices, i.e. view for iPhone 4, another view for iPhone 5, etc. More information can be found.

+3


source







All Articles