2010-01-24 130 views
6

我正在關注Chris Pietschmann的solution for theming in ASP.NET MVCASP.NET MVC ViewEngine ViewLocationCache.GetViewLocation返回null

我注意到的一件事是,在後續請求中,ViewLocationCache沒有檢索視圖名稱。 我使用ASP.NET MVC 2.0 RC

當執行以下代碼:

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

,我將鼠標懸停在this.ViewLocationCache它只是返回{} System.Web.Mvc.NullViewLocationCache - 提示什麼都沒有添加?

回答

10

ViewLocationCache默認情況下僅在發佈模式下可用(設置<compilation debug="false">web.config)。

在調試模式下啓用ViewLocationCache
在從WebFormViewEngine繼承的自定義視圖引擎,設置ViewLocationCache在你的視圖引擎的構造函數,像這樣:

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

您還可以,如果覆蓋默認的緩存時間跨度值你希望。