How would I go about creating an admin page to clear the cache on a CD server? Looking at this question/answer I would assume the following:

  1. Define a new cache:clear custom event in a new config patch file.
  2. Create a cs file to handle this custom event
  3. Create an admin aspx page (hosted on the CM server) to enable firing the event

Are there any other things I've missed here?

For the event handler, I was thinking something along the lines of

var siteContext = Sitecore.Sites.SiteContextFactory.GetSiteContext("MySite");
var cache = Sitecore.Caching.CacheManager.GetHtmlCache(siteContext);
  • The admin page will not work on Sitecore 9.X on CD servers because there is no more Core database there. hence you will not be able to login on the admin page Commented Oct 14, 2019 at 19:32
  • Wouldn't a publish do this? isn't one of the publish:end events to clear the cache? Or maybe that is just HtmlCache
    – Chris Auer
    Commented Oct 14, 2019 at 19:50
  • @ChrisAuer yes, a publish does clear the cache, but commerce is involved here and I would like to be certain that the whole HTML cache has been cleared and ideally would like to do that without the need to publish as well. Commented Oct 14, 2019 at 20:19
  • If you create an aspx file in the web root with your code, you could run a one-off, then delete the file. Commented Oct 15, 2019 at 0:28

1 Answer 1


You can create "Code Beside" pages in ASPX/C# that embeds a small amount of code. We sometimes need to see which Solr cores are connected where (when troubleshooting) as we version our Solr with each new release.

To do that we use Azure's "App Service Editor" to open an in-browser VS Code instance pointed at the running production site.


Yes, this is very dangerous - it's only for troubleshooting so take appropriate protective measures and for God's sake don't edit config files unless you're prepared for an app recycle - THE FILES HERE ARE AUTO-SAVED!!

Anyway, back to the code. If you create an .ASPX file you can just plonk code in thus:

<% @Page Language="C#" %>
     <% foreach( var core in Sitecore.ContentSearch.SolrProvider.SolrContentSearchManager.Cores ) { %>
          <li><% = core %></li>
     <% } %>

This will obviously execute when you load the page. You can use a similar technique to clear caches selectively or en masse.

If you want to leave a bunch of little pages like this, create a folder and call it __ (double underscore) or something non-collision-ey. Adjust the web.config to IP lock that folder to your company, that makes it marginally safer.

  • Yeah I am not a fan of the auto-save. Been using Kudo instead so that I don't have any mishaps :P Commented Oct 15, 2019 at 0:51
  • 2
    @DaveGoosem it's a dirty dirty hack, but sometimes that's just what is called for! Commented Oct 15, 2019 at 15:48

Your Answer

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

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