I created a website using ASPNET.MVC4 RC. For each view I created 2 files like index.cshtml and index.Mobile.cshtml which represent desktop and mobile views. Out of the box everything is working fine – mobile devices get mobile view and non-mobile devices get full desktop view.
However I have a problem trying to force desktop view onto the mobile devices (i.e. when user clicks on “Full site” link) – view does not change and mobile view still gets rendered.
I use following code to override browser (called from global filter):
filterContext.RequestContext.HttpContext.SetOverriddenBrowser(BrowserOverride.Desktop);
I can see that following cookie gets set:.ASPXBrowserOverride=[Mozilla%2f4.0+(compatible%3b+MSIE+6.1%3b+Windows+XP)] as result of this call, but obviously it gets ignored for some reason.
Forcing mobile view on desktop browsers works fine, i.e. other way around.
Any help would be greatly appreciated.
Thanks.
I have found where my problem was. In case somebody falls into the same trap, here is what it was:
When I was creating my project I took contents for my device configuration class, which adds mobile DefaultDisplayMode to DisplayModeProvider, from support answer I found on Microsoft support forums.
That code was looking for mobile device specific strings in Request.UserAgent. However SetOverriddenBrowser() method changes only overridden user agent, Request.UserAgent remains untouched.
So solution is to replace
Request.UserAgentwithContext.GetOverriddenUserAgent()when analyzing client’s request.