10

I've just followed Scott Hanselmans tutorial on making a switchable site in MVC4.

I'm using the Opera mobile emulator to test as I don't have VS2102.

When rendering my page in the emulator Request.Browser.IsMobileDevice is false although it still renders the mobile view.

enter image description here

My questions are:

  • Why/How does MVC4 decide to render the mobile view? It doesn't seem like it looks at Request.Browser.IsMobileDevice.
  • Will the View Switcher be displayed on a real mobile device?

Edit:

I think I realised my mistake:

To get it to work with the opera emulator I added a MobileDisplayMode as described here: ASP.NET MVC 4 Mobile Features

It seems that that solution works with rendering correctly but Request.Browser.IsMobileDevice won't work. The same goes for ViewContext.HttpContext.GetOverriddenBrowser().IsMobileDevice is there a way to get around this?

Community
  • 1
  • 1
woggles
  • 7,444
  • 12
  • 70
  • 130
  • EHMAGEHD, This post is from the future!!! *I'm using the Opera mobile emulator to test as I don't have VS2102.* :) – Jamiec Oct 03 '12 at 14:20
  • I see you mention you are using Opera Mobile to test. You can also use WebMatrix to emulate iPhone, iPad, WP7 etc. or in Chrome Ctrl Shift + i then Settings > Override and choose the UserAgent you want to send with the requests. – Jive Boogie Oct 03 '12 at 14:23
  • 1
    haha yep you caught me out...im working on a legacy mvc4 app, Microsoft fix browser detection in MVC11 :) – woggles Oct 03 '12 at 14:24
  • When changing user agents in chrome it doesn't render the mobile view at all – woggles Oct 04 '12 at 08:02

1 Answers1

5

MVC recognize Mobile device by matching the HTTP request header with browser config files present in C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\Browsers

The asp.net MVC browser detection approach is not great so i recommend using some sort of DDR

Ajay Beniwal
  • 18,857
  • 9
  • 81
  • 99
  • I have a question, is it possible to override this configuration via browserCaps.config? NB: i am using 51degrees.mobi . – nirupam Jul 23 '13 at 10:37