2

I have a single ASP.NET MVC app which uses areas to deliver different functionality depending which url is hit. For example

  • www.domain.com - Website Area
  • app.domain.com - Application Area
  • *.domain.com - Client Area

So, the point is that depending on the incoming url, we route you to a different MVC Area. This is all done using Routing with some extensions and works great.

Now, if I enable outputcache on the Index() Action for my www default route, the next time i hit app.domain.com, i get the cached version of the www domain. I checked using fiddler and the response is a 200 OK so it's definately hitting the server. However, the logging in my custom routing tells me it's not hitting that code.

So, does OutputCache not work based off the uri and instead uses some other algorithm?

Thanks

Yannick Blondeau
  • 9,465
  • 8
  • 52
  • 74
James
  • 720
  • 9
  • 19

2 Answers2

2

[OutputCache(VaryByHeader="Host")] should help.

Zygimantas
  • 8,547
  • 7
  • 42
  • 54
0

The behavior will depend on where you decided to store the cache (Location property). Ifv you stored the cache on the server (OutputCacheLocation.Server) then the result from the execution of the action will be stored on the server and when a subsequent request is made to this action, the server will be hit and it will directly return the cached version without executing the controller action which is the behavior you describe.

If you store the cache on the client (OutputCacheLocation.Client), then the cache will be kept on the client browser. In this case if a subsequent request is made to the same action, the client will no longer hit the server but will directly serve the page from its cache. And remember that if you hit F5 in your browser you will expire the cache for the given page, so the server will be hit.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • Thanks for the reply. It's setup as default so assuming it's set to server. I still don't think this is correct though because it's returning the cached version of a different action (sub.domain.com returns the www.domain.com cached page). – James Mar 10 '12 at 08:41
  • @James, indeed, that doesn't seem right. You mentioned some custom code for the routing. Could you show how this is done? – Darin Dimitrov Mar 10 '12 at 09:33
  • I'm using DomainRoutes http://blog.maartenballiauw.be/post/2009/05/20/ASPNET-MVC-Domain-Routing.aspx to restrict routes to certain domains. These routes are registered in each AreaRegistration – James Mar 12 '12 at 10:42