Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 942
Cros Avatar asked May 08 '12 07:05

Cros


People also ask

How can I view my asp net website on mobile devices?

Put your mobile device in your lan and then type http://<ip adresse of the host computer>/<name of the website> into adress bar from browser on your mobile device.

How to use site mobile master in ASP net?

You can add an area called "Mobile" to an existing ASP.NET MVC application in the normal way: right-click on your project name in Solution Explorer, then choose Add à Area. You can then add controllers and views as you would for any other area within an ASP.NET MVC application.

What is the purpose of view in an MVC application?

A View, in the context of a Model View Controller (MVC) architecture, is a software class that contains a template and data form and produces a response for the browser. It receives data from the Controller of the MVC and packages it and presents it to the browser for display.

Should each view have a controller?

Absolutely not. Design your application in a logical and consistent way. A controller usually handles many actions and returns many different views. You could consider having a FAQController to render all the views, for both user and admin.


1 Answers

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

like image 56
tugberk Avatar answered Sep 20 '22 17:09

tugberk