1

I need to patch in a fix for a bug with Sitecore MVC Caching (confirmed by support).

The pipeline I need to patch into is:

I need to set cache settings on the page object, e.g:

page.Response.Cache.SetCacheability(HttpCacheability.NoCache);

However to do that I need access to the System.Web.UI.Page.

Whatever I try the page is coming up null:

PageContext page = Context.Page;
Page page = HttpContext.Current.Handler as Page;
Page page = Sc.Context.Page.Page;

I know I can use:

Page page = PageContext.CurrentOrNull.Item;

To get the Sitecore page item but I need the System.Web.UI.Page, not the item.

I'm guessing this is due to the order in which the MVC Pipelines run etc: http://jockstothecore.com/sitecore-mvc-item-maze/

Any help would be appreciated.

Other info: Sitecore 8.1 Update 2, MVC

2
  • Makes no sense to me. System.Web.UI.Page is the class you inherit in an .aspx file, e.g. a Webforms layout. It would not come into play in MVC. Sep 7, 2017 at 16:21
  • 1
    Ahr yes your right Mark, I'm being a bit of an idiot. I've got it working now, just needs to be HttpContext.Current.Response.Cache.SetNoStore(); Sep 7, 2017 at 16:34

1 Answer 1

2

As mentioned in the comments I was going about this in the wrong way for MVC. This is the solution for my pipeline:

public override void Process(GetPageRenderingArgs args)
        {
            Assert.ArgumentNotNull((object)args, "args");
            Profiler.StartOperation("Update browser caching headers.");
            HttpContext currentContext = HttpContext.Current;
            Item currentItem = PageContext.CurrentOrNull.Item;

            if (currentContext == null)
                return;

            MvcBrowserCaching.SetCacheHeaders(currentContext);

            if (currentItem != null)
                MvcBrowserCaching.SetUpdateHeaders(currentItem, currentContext);

            Profiler.EndOperation();
        }

I can then set the cache like so:

currentContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.