Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post May 24, 2012 02:07 AM by Young Yang - MSFT
May 17, 2012 09:54 AM|LINK
I have recently come across the Last-Modified Header.
May 17, 2012 10:12 AM|LINK
You can include it in MVC anywhere you can get access to the Cache object, which is typically through the Response object:
The advantage is it allows clients that have visited your page before to not download static files (like images that don't change) they have in browser cache, so the site will seem faster.
Last-Modified HTTP header explained
When a visitor browses your website, his/her browser caches your images, html, style sheet and other files locally for better performance. If you have the so-called "Last-Modified" header set in your pages, next time when the same visitor loads your website, the server will check whether there is a change in the files since the last time they have been accessed.
If there is no change, the server will send a "304 Not Modified" reply to the browser and the information will be loaded from the local cache. If you do not update your website very often, using "Last-modified" headers can significantly increase its loading speed.
May 17, 2012 10:13 AM|LINK
How and where can I include it in MVC?
I think that you can include more in WebAPI rather in MVC
see an example for etag here : http://tudorturcu.wordpress.com/
What are the advantages of including it?
May 17, 2012 11:19 AM|LINK
Darell, thanks for the explanation. Do I have to include it per action or per controller? In my project I am having some 7 controller, each with some 5 actions minimum. Where should I include it? What is someDateTime? How Do I determine that value? Is
it some fixed values in date, time, seconds.
May 18, 2012 10:56 AM|LINK
May 24, 2012 02:07 AM|LINK
You can create an extension method, like this:
public static class CacheExtensions
public bool IsModified(Controller controller, DateTime updatedTime)
var header = controller.Request.Headers['If-Modified-Since'];
if (header != null)
var modifiedTime = DateTime.Parse(header).ToLocalTime();
if (modifiedTime >= updatedTime)
public ActionResult NotModified(Controller controller)
return new HttpStatusCodeResult(304, "Page has not been modified");
public class YourController : Controller
public ActionResult YourAction(string id)
var entity = _db.Get(id);
Hope this helpful