Reputation: 61287
I have a web application which was using Asp.net MVC2. I Upgraded it to MVC 3 and now I found that OutputCache feature is not working any-more. I created a simple Test action as shown below.
[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();
}
This always gives the current time which shows that it is not cached. Am I missing something here?
More Info: If i create a new Mvc3 app it works fine. Its only in the upgraded app that I have this issue.
Update: I am also using Ninject. If I stop using Ninject OutputCache starts working.
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();
}
}
Upvotes: 3
Views: 548
Reputation: 1039298
The correct and recommended way to use Ninject in ASP.NET MVC 3 is the following:
Install the ninject.mvc3
NuGet package. This will ensure that you get the latest version compatible with ASP.NET MVC 3.
Once installed this will add a App_Start/NinjectMVC3.cs
file to your project and it is inside the RegisterServices
method that you will register your Ninject modules:
private static void RegisterServices(IKernel kernel)
{
var modules = new INinjectModule[]
{
// your modules here
};
kernel.Load(modules);
}
Remove all Ninject specific code from your Global.asax including any NinjectDependencyResolver
.
Try following those steps and maybe your problem will get fixed.
Upvotes: 6