diff --git a/src/Umbraco.Web/Editors/StylesheetController.cs b/src/Umbraco.Web/Editors/StylesheetController.cs
index 38318541a4..535351a14f 100644
--- a/src/Umbraco.Web/Editors/StylesheetController.cs
+++ b/src/Umbraco.Web/Editors/StylesheetController.cs
@@ -22,8 +22,7 @@ namespace Umbraco.Web.Editors
///
/// The API controller used for retrieving available stylesheets
///
- [PluginController("UmbracoApi")]
- [DisableBrowserCache]
+ [PluginController("UmbracoApi")]
public class StylesheetController : UmbracoAuthorizedJsonController
{
public IEnumerable GetAll()
diff --git a/src/Umbraco.Web/Editors/TemplateQueryController.cs b/src/Umbraco.Web/Editors/TemplateQueryController.cs
index 4b81715ead..2eaf63f159 100644
--- a/src/Umbraco.Web/Editors/TemplateQueryController.cs
+++ b/src/Umbraco.Web/Editors/TemplateQueryController.cs
@@ -18,7 +18,6 @@ namespace Umbraco.Web.Editors
/// The API controller used for building content queries within the template
///
[PluginController("UmbracoApi")]
- [DisableBrowserCache]
[JsonCamelCaseFormatter]
public class TemplateQueryController : UmbracoAuthorizedJsonController
{
diff --git a/src/Umbraco.Web/Editors/UmbracoAuthorizedJsonController.cs b/src/Umbraco.Web/Editors/UmbracoAuthorizedJsonController.cs
index e60abe0859..30ffd26e12 100644
--- a/src/Umbraco.Web/Editors/UmbracoAuthorizedJsonController.cs
+++ b/src/Umbraco.Web/Editors/UmbracoAuthorizedJsonController.cs
@@ -13,6 +13,7 @@ namespace Umbraco.Web.Editors
///
[ValidateAngularAntiForgeryToken]
[AngularJsonOnlyConfiguration]
+ [DisableBrowserCache]
public abstract class UmbracoAuthorizedJsonController : UmbracoAuthorizedApiController
{
protected UmbracoAuthorizedJsonController()
diff --git a/src/Umbraco.Web/Mvc/DisableBrowserCacheAttribute.cs b/src/Umbraco.Web/Mvc/DisableBrowserCacheAttribute.cs
new file mode 100644
index 0000000000..c1b5b88643
--- /dev/null
+++ b/src/Umbraco.Web/Mvc/DisableBrowserCacheAttribute.cs
@@ -0,0 +1,24 @@
+using System;
+using System.Web;
+using System.Web.Mvc;
+
+namespace Umbraco.Web.Mvc
+{
+ ///
+ /// Ensures that the request is not cached by the browser
+ ///
+ public class DisableBrowserCacheAttribute : ActionFilterAttribute
+ {
+ public override void OnActionExecuted(ActionExecutedContext filterContext)
+ {
+ base.OnActionExecuted(filterContext);
+
+ filterContext.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);
+ filterContext.HttpContext.Response.Cache.SetMaxAge(TimeSpan.Zero);
+ filterContext.HttpContext.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
+ filterContext.HttpContext.Response.Cache.SetNoStore();
+ filterContext.HttpContext.Response.AddHeader("Pragma", "no-cache");
+ filterContext.HttpContext.Response.Cache.SetExpires(new DateTime(1990, 1, 1, 0, 0, 0));
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Umbraco.Web/Mvc/UmbracoAuthorizedController.cs b/src/Umbraco.Web/Mvc/UmbracoAuthorizedController.cs
index a70bc47cb9..9229939d0f 100644
--- a/src/Umbraco.Web/Mvc/UmbracoAuthorizedController.cs
+++ b/src/Umbraco.Web/Mvc/UmbracoAuthorizedController.cs
@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
-using System.Web.Mvc;
using Umbraco.Core.Configuration;
using Umbraco.Web.Routing;
using Umbraco.Web.Security;
@@ -18,6 +17,7 @@ namespace Umbraco.Web.Mvc
/// authorization of each method can use this attribute instead of inheriting from this controller.
///
[UmbracoAuthorize]
+ [DisableBrowserCache]
public abstract class UmbracoAuthorizedController : UmbracoController
{
diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj
index 9778cee6e0..7aec0b676f 100644
--- a/src/Umbraco.Web/Umbraco.Web.csproj
+++ b/src/Umbraco.Web/Umbraco.Web.csproj
@@ -343,6 +343,7 @@
+
diff --git a/src/Umbraco.Web/WebApi/Filters/DisableBrowserCacheAttribute.cs b/src/Umbraco.Web/WebApi/Filters/DisableBrowserCacheAttribute.cs
index c526317d95..e1890326fb 100644
--- a/src/Umbraco.Web/WebApi/Filters/DisableBrowserCacheAttribute.cs
+++ b/src/Umbraco.Web/WebApi/Filters/DisableBrowserCacheAttribute.cs
@@ -13,6 +13,9 @@ using Umbraco.Core;
namespace Umbraco.Web.WebApi.Filters
{
+ ///
+ /// Ensures that the request is not cached by the browser
+ ///
public class DisableBrowserCacheAttribute : ActionFilterAttribute
{
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
@@ -21,23 +24,16 @@ namespace Umbraco.Web.WebApi.Filters
base.OnActionExecuted(actionExecutedContext);
- //TODO: This should all work without issue! BUT it doesn't, i have a feeling this might be fixed
- // in the next webapi version. ASP.Net is overwriting the cachecontrol all the time, some docs are here:
- // http://stackoverflow.com/questions/11547618/output-caching-for-an-apicontroller-mvc4-web-api
- // and I've checked the source code so doing this should cause it to write the headers we want but it doesnt.
- //So I've reverted to brute force on the HttpContext.
- //actionExecutedContext.Response.Headers.CacheControl = new CacheControlHeaderValue()
- //{
- // NoCache = true,
- // NoStore = true,
- // MaxAge = new TimeSpan(0),
- // MustRevalidate = true
- //};
-
- HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
- HttpContext.Current.Response.Cache.SetMaxAge(TimeSpan.Zero);
- HttpContext.Current.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
- HttpContext.Current.Response.Cache.SetNoStore();
+ //NOTE: Until we upgraded to WebApi 2, this didn't work correctly and we had to revert to using
+ // HttpContext.Current responses. I've changed this back to what it should be now since it works
+ // and now with WebApi2, the HttpContext.Current responses dont! Anyways, all good now.
+ actionExecutedContext.Response.Headers.CacheControl = new CacheControlHeaderValue()
+ {
+ NoCache = true,
+ NoStore = true,
+ MaxAge = new TimeSpan(0),
+ MustRevalidate = true
+ };
actionExecutedContext.Response.Headers.Pragma.Add(new NameValueHeaderValue("no-cache"));
if (actionExecutedContext.Response.Content != null)