2
Vote

PreemptPhysicalFiles ignored on partial views

description

The PreemptPhysicalFiles = false works for views, but when RenderPartial is called the cshtml file from assembly is used even the file exist on disk.

There is missing condition for PreemptPhysicalFiles in FileExists, but the condition is present in CreateInstance. I fixed it by overriding the FileExists method.
public class PrecompiledMvcEngineFixed : PrecompiledMvcEngine
    {
        protected override bool FileExists(ControllerContext controllerContext, string virtualPath)
        {
            if (!PreemptPhysicalFiles && VirtualPathProvider.FileExists(virtualPath))
            {
                // If the physical file on disk exist and the user's opted in this behavior, serve it instead.
                return false;
            }
            return base.FileExists(controllerContext, virtualPath);
        }
    }
Note that it works OK when engine is added at the end:
ViewEngines.Engines.Add(engine);
However it does not work when engine is put at the 1st place:
ViewEngines.Engines.Insert(0,engine);

comments

davidebbo wrote Feb 18, 2013 at 9:36 PM

Could you send a pull request with the change? Thanks!

pub wrote Feb 19, 2013 at 12:23 PM