ASP.NET MVC 4 Mobile Features

ASP.Net (actually the HttpBrowserCapabilitiesBase class) doesn’t recognize the Opera Mobile Emulator as a Mobile browser.

You can check this in any controller action: HttpContext.Request.Browser.IsMobileDevice will return false for the Opera Mobile browser.

Because the built in DefaultDisplayMode uses the following method to check mobile browsers you need to register your custom DisplayMode which correctly recognizes Opera Mobile.

To do this you need to add this to the Global.asax Application_Start:

DisplayModeProvider.Instance.Modes.Insert(0, new DefaultDisplayMode("Mobile")
{
    ContextCondition = (context => context.GetOverriddenUserAgent()
        .IndexOf("Opera Mobi", StringComparison.OrdinalIgnoreCase) >= 0)
});

Leave a Comment