in my asp.net mvc project, I enable output caching on a controller as below
[OutputCache(Duration = 100, VaryByParam = "*", VaryByHeader = "X-Requested-With")]
public class CatalogController : BaseController
{
public ActionResult Index(string seller)
{
// I do something
}
}
it works great, until create my own Route class as below
public class MyRoute : Route
{
// there is a constructor here..
// I override this method..
// just to add one data called 'seller' to RouteData
public override RouteData GetRouteData(HttpContextBase httpContext)
{
var data = base.GetRouteData(httpContext);
if (data == null) return null;
var seller = DoSomeMagicHere();
// add seller
data.Values.Add("seller", seller);
return data;
}
}
and then, the action method will take seller
as parameter. I tested it by always providing different seller
parameter, but it take the output from cache instead of calling the method.
does setting VaryByParam="*" also vary by RouteData.Values, in asp.net mvc?
I'm using ASP.Net 4 MVC 3 RC 2
See Question&Answers more detail:os