This is due to how OutputCacheAttribute works, namely, its dependency on a RouteData -null RouteData . Relevant Part:
public override void OnResultExecuting(ResultExecutingContext filterContext) { if (filterContext == null) { throw new ArgumentNullException("filterContext"); } if (!filterContext.IsChildAction) { new OutputCachedPage(this._cacheSettings).ProcessRequest(HttpContext.Current); } }
ResultExecutingContext filterContext derived from ControllerContext . This is the source for ControllerContext.IsChildAction :
public virtual bool IsChildAction { get { RouteData routeData = this.RouteData; if (routeData == null) { return false; } return routeData.DataTokens.ContainsKey("ParentActionViewContext"); } }
So why does this apply to your question?
Because when you omit the "/", your Route doesn't match anything. The default route is " / ". An article explaining this in more detail is given here: http://www.58bits.com/blog/2008/09/29/ASPNet-MVC-And-Routing-Defaultaspx.aspx . This was written to explain why the Default.aspx needed in ASP.NET MVC 1 projects, but the reason lies in the same place.
So basically, RouteData is null, so OutputCacheAttribute cannot work. You can solve your problem by doing what Michael Jasper suggested and using URL rewriting.
source share