Search code examples
asp.net-mvccachingasp.net-mvc-routingmvc-mini-profiler

And still, what is the magic of ASP.NET MVC Content folder?


I've just moved my resource files (javascript, css, images) from Content folder to custom Assets folder. And I've noticed a strange behavior - these files are not longer cached by browser and MvcMiniProfiler shows separate request for each resource located in Assets folder:

Before moving to Assets folder and after

I know that Content folder isn't required by ASP.NET MVC convention, but why this happens? Is Content treated somehow especially by anyone (e.g. ASP.NET, IISExpress, etc.)? And how to force caching for other folders that contain static resources?

EDIT: Oh, it appears to be not an ASP.NET MVC odd behavior, but just the standard behavior of MvcMiniProfiler. Currently I'm checking that...

EDIT: Yea, there is no problem with ASP.NET MVC, it's just a default configuration of MvcMiniProfiler to ignore only these paths: "/mini-profiler-", "/content/", "/scripts/", "/favicon.ico". And these defaults can be easily extended:

MiniProfiler.Settings.IgnoredPaths = MiniProfiler.Settings.IgnoredPaths
    .Concat(new [] { "/assets/" })
    .ToArray();

Sometimes it's a good idea to read documentation before using something ;)


Solution

  • As you're indicating in your update, this appears to be a feature of MvcMiniProfiler:

    /// <summary>
    /// When <see cref="MiniProfiler.Start"/> is called, if the current request url contains any items in this property,
    /// no profiler will be instantiated and no results will be displayed.
    /// Default value is { "/mini-profiler-", "/content/", "/scripts/", "/favicon.ico" }.
    /// </summary>
    [DefaultValue(new string[] { "/mini-profiler-", "/content/", "/scripts/", "/favicon.ico" })]
    public static string[] IgnoredPaths { get; set; }
    

    Source.

    Presumably, the images were never cached when you were serving them through Cassini, because Cassini is terrible at that (passing png files as application/octet-stream, for instance), but the issue was manually hidden from your view by MvcMiniProfiler.