我有一個網絡應用程序使用Asp.net MVC2。我將其升級到MVC 3,現在我發現OutputCache功能無法正常工作。我創建了一個簡單的測試操作,如下所示。從MVC 2升級後,Asp.net MVC 3不能與Ninject一起工作?
[OutputCache(Duration = 1000000, VaryByParam = "none")]
public virtual ActionResult CacheTest(string name)
{
string message = string.Format("{0}: Time is {1}", name, DateTime.Now.ToLongTimeString());
ViewData.Add("Message", message);
return View();
}
這總是給人當前時間這表明它不緩存。我在這裏錯過了什麼嗎?
更多信息:如果我創建一個新的Mvc3應用程序它工作正常。它只在升級的應用程序,我有這個問題。
更新:我也在使用Ninject。如果我停止使用Ninject OutputCache開始工作。
public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}.aspx/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
protected void Application_Start()
{
RegisterDependencyResolver();
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
}
protected void RegisterDependencyResolver()
{
var kernel = CreateKernel();
DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel));
}
protected IKernel CreateKernel()
{
return new StandardKernel();
}
}
奇怪,我無法重現該問題。緩存適用於我。 –
如果我創建一個新的Mvc3應用程序,它工作正常。它只在升級的應用程序,我有這個問題。 – Amitabh
這一切都沒有意義。對我來說,這個a)不能被重新編譯b)僅僅是沒有意義 - Ninject只是和'OutputCacheAttribute'沒有關係,所以必須有一些東西搞砸了,比如有多個Ninject或MVC版本在玩。另請參閱https://groups.google.com/forum/?fromgroups=#!topic/ninject/NtsBWNS4MJs –