Cros
Cros

Reputation: 4377

Why do mobile views in ASP.NET MVC display differently on different servers?

I am using the new ASP.NET MVC 4 beta and am trying to create a system that mostly works with responsive design, but for one specific view I am using a mobile view to render a specific view for mobile devices.

My structure is simply that I have a Show.cshtml and following that I have a Show.mobile.cshtml.

If I make my site available from my dev machine through IIS Express this view displays correctly for iPad, iPhone, Android phones and mobile Opera, and it also works the same if I make a local publish to IIS 7.5 on my dev machine.

The problem comes when we deploy to a live server, we have tried deploying on two different servers. Then the mobile view will only be served to iPhones, no other mobile devices. This is consistently so. Our servers set up have been both Windows 2003/IIS6 and Windows 2008 R2/IIS7.5 and it works the same on both, only iPhone gets served the mobile view.

What might be the cause of this?

I have not added anything custom in global.asax for this.

UPDATE

After some more research it seems clear to me that the default behavior for DisplayMode and mobile views depends on the Request.Browser.IsMobileDevice flag. This flag in turn seems to rely on the .browser files that are in the Config/Browsers-folder of the .NET Framework folder.

On my dev machine I have different .browser files than those that are present on the servers I have deployed to. So far I have tried to deploy the ones I have on my machine in the App_Browsers-folder of the web app, but that did not fix my issue. Might this be the way to go?

Upvotes: 17

Views: 1868

Answers (2)

David Smit
David Smit

Reputation: 839

I thought the solution I gave below was the answer (it worked for a brief moment), but it still switched to the wrong view after a while.

Like the rest of the internet, I installed 51 Degrees from Nuget This is working perfectly, and is very easy to set up


(The below doesn't work for me, but maybe it does for you) http://www.nuget.org/packages/Microsoft.AspNet.Mvc.FixedDisplayModes

Looks like it is a known bug: http://aspnetwebstack.codeplex.com/workitem/280?PendingVoteId=280

According to codeplex link above, remember to make sure of this :

For a small set of projects that customize the list of registered view engines (for example, in Global.asax) you should make sure that you are referencing Microsoft.Web.Mvc.FixedRazorViewEngine or Microsoft.Web.Mvc.FixedWebFormViewEngine, instead of the classes that ship in the core runtime binary

Upvotes: 0

tugberk
tugberk

Reputation: 58444

This is not a complete answer to your question but I think it will still help.

ASP.NET is not very good at solving browser capabilities in my experience. So, I can recommend looking into 51Degrees.Mobi Foundation. Steven Sanderson has a nice blog post on that:

Using 51Degrees.Mobi Foundation for accurate mobile browser detection on ASP.NET MVC 3

I am not completely sure but you should be able to hook this up easily to ASP.NET MVC 4 DisplayMode infrastructure. Here is a good resource on that:

51Degrees.mobi and MVC4

Upvotes: 6

Related Questions