ASP.NET MVC视图引擎ViewLocationCache.GetViewLocation返回null。

6

我正在遵循Chris Pietschmann在ASP.NET MVC主题化解决方案

我注意到的一件事是,视图名称在后续请求中没有从ViewLocationCache中检索。 我正在使用ASP.NET MVC 2.0 RC

当执行以下代码时:

this.ViewLocationCache.InsertViewLocation(controllerContext.HttpContext, cacheKey, virtualPath);

当我悬停在 this.ViewLocationCache 上时,它只返回 {System.Web.Mvc.NullViewLocationCache} - 这是否意味着什么都没有被添加?
1个回答

10

ViewLocationCache 默认只在发布模式下生效(在 web.config 中设置 <compilation debug="false">)。

要在调试模式下启用 ViewLocationCache
在继承自 WebFormViewEngine 的自定义视图引擎中,可以在 ViewEngine 构造函数中设置 ViewLocationCache,如下所示:

public MyCustomViewEngine()
{
    ViewLocationCache = new DefaultViewLocationCache();
}

如果您愿意,您还可以覆盖默认的缓存时间跨度值。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接