17

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?

4

2 回答 2

6

这不是您问题的完整答案,但我认为它仍然会有所帮助。

以我的经验,ASP.NET 不太擅长解决浏览器功能。所以,我可以推荐查看51Degrees.Mobi Foundation。史蒂文·桑德森对此有一篇很好的博客文章:

使用 51Degrees.Mobi Foundation 在 ASP.NET MVC 3 上进行准确的移动浏览器检测

我不完全确定,但您应该能够轻松地将其连接到 ASP.NET MVC 4 DisplayMode 基础架构。这是一个很好的资源:

51Degrees.mobi 和 MVC4

于 2012-05-08T11:33:12.350 回答
0

我认为我在下面给出的解决方案就是答案(它工作了一会儿),但一段时间后它仍然切换到错误的视图。

像互联网的其他部分一样,我从 Nuget 安装了 51 Degrees 这运行良好,而且很容易设置


(下面对我不起作用,但也许对你有用) http://www.nuget.org/packages/Microsoft.AspNet.Mvc.FixedDisplayModes

看起来这是一个已知的错误:http ://aspnetwebstack.codeplex.com/workitem/280?PendingVoteId=280

根据上面的 codeplex 链接,请记住确保这一点:

对于自定义已注册视图引擎列表的一小部分项目(例如,在 Global.asax 中),您应该确保您引用的是 Microsoft.Web.Mvc.FixedRazorViewEngine 或 Microsoft.Web.Mvc.FixedWebFormViewEngine,而不是核心运行时二进制文件中的类

于 2013-07-24T12:10:57.507 回答