Partager via


ASP.NET MVC 4 Mobile Caching Bug Fixed

31 October 2012 Update: The ASP.NET Fall 2012 Update includes the Fixed DisplayModes NuGet package in the new project templates.  You will still need to apply the Fixed DisplayModes NuGet package to projects created before you install the ASP.NET Fall 2012 Update.

The RC and RTM versions of ASP.NET MVC 4 had a bug in the view caching mechanism that resulted in mobile views (and other views specified by inserting a new DefaultDisplayMode)  returning the wrong view.  Initially the correct mobile view would be returned, but when the mobile view expired from the cache (which has a sliding default of 15 minutes) and when the desktop view was still in the cache, a mobile request for the view would return the desktop view. This bug was reported as bug number 280 on CodePlex and in the ASP.NET MVC forum here.

Most applications that hit this problem can simply install the Fixed DisplayModes NuGet package. The ASP.NET Fall 2012 Update includes the Fixed DisplayModes NuGet package in the new project templates.

Applications that customize the collection of registered view engines will need to reference the fixed razor or fixed web forms view engine:

  • Microsoft.Web.Mvc.FixedRazorViewEngine
  • Microsoft.Web.Mvc.FixedWebFormViewEngine

Applications that remove all the view engines, then add back Razor with the following code:

 ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new RazorViewEngine());
 
 
 
 
 

Will need to replace the above code with the following:

 ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new Microsoft.Web.Mvc.FixedRazorViewEngine());
 

In addition to blogging, I use Twitter to make quick posts and share links. My Twitter handle is: @RickAndMSFT

Comments

  • Anonymous
    September 18, 2012
    Hi, We found another issue with using multiple view engines with desktop and mobile (aspnetwebstack.codeplex.com/.../276). We have now worked around it by making both view engines use the same cache. Do you know if you guys are ever likely to support this configuration?

  • Anonymous
    October 31, 2012
    @stevejhiggs Thank you for reporting the issue. Unfortunately, having a different view engine for the desktop and mobile views is not supported.

  • Anonymous
    January 02, 2013
    its not perfectly working sometimes it lags some views still !! anybody knows if i downgrade to mvc3.0 problem will be solved?!

  • Anonymous
    July 06, 2013
    and if you're using a custom viewengine you can just extend Microsoft.Web.Mvc.FixedRazorViewEngine