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} - 暗示没有添加任何内容?

4

1 回答 1

10

ViewLocationCache默认情况下仅在发布模式下工作(设置<compilation debug="false">web.config)。

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

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

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

于 2010-01-27T12:51:44.547 回答