Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.net MVC 3 output cache based on domain

Im developing an asp.net mvc 3 site that serves multiple domains. So based on the domains I show different content.

For example if its www.domain1.com, in homepage I show 3 images and some text. If its www.domain2.com in homepage I show only text.

I implemented a custom output cache provider called FileOutputCache, which saves the cached pages into files, and I would like to us it in this project. But I have a BIG problem, I dont have access to the request, nor to the host...

This is one of the operations: public override object Add(string key, object entry, DateTime utcExpiry);

You can see that I have no access to the host, and the key doesnt depend on it... So if I deploy the site and the first user enters to www.domain1.com, it will render and cache the page with 3 images and text.... and if another user enters to www.domain2.com, it will show the 3 images and text :(

Does anyone know how can I differentiate the request's host in my custom output cache provider?

Thanks in advance! Juan

like image 449
Juan Avatar asked Jun 09 '11 13:06

Juan


1 Answers

I solved this by using VaryByHeader = Host

As the domain is in the host, which is a header, you can just use that built-in asp.net mvc functionality and it works fine.

like image 199
Juan Avatar answered Sep 28 '22 04:09

Juan