Clear ARR cache programmatically using Microsoft.Web.Administration;
using System;
namespace IISCacheManager
{
class Program
{
static void Main(string[] args)
{
if (args.Length != 1)
{
Console.WriteLine("Incorrect Usage: Specify the URL that you want to flush the cache for. To delete everything, specify 'ALL'.");
Environment.Exit(1);
}
var url = args[0] == "ALL" ? string.Empty : args[0];
var m = new ServerManager();
var x = m.GetApplicationHostConfiguration().GetSection("system.webServer/diskCache");
var method = x.Methods["FlushUrl"].CreateInstance();
method.Input.SetAttributeValue("url", url);
method.Execute();
Console.WriteLine("Item flushed successfully.");
}
}
}
Note that in order for this to work, you need to elevate permissions to run as an Administrator or you'll get some nice ACCESS DENIED errors. You also need to reference Microsoft.Web.Administration from the GAC