asp.net-mvc - 而且,ASP.NET MVC Content文件夹的神奇之处是什么?

标签 asp.net-mvc caching asp.net-mvc-routing mvc-mini-profiler

我刚刚将资源文件(javascript,css,图像)从Content文件夹移到了自定义Assets文件夹。而且我注意到了一个奇怪的行为-这些文件不再被浏览器缓存,并且MvcMiniProfiler显示了对Assets文件夹中每个资源的单独请求:

我知道ASP.NET MVC约定不需要Content文件夹,但是为什么会这样呢?有人对Content进行了特别的处理吗(例如ASP.NET,IISExpress等)?以及如何强制缓存包含静态资源的其他文件夹?

编辑:哦,它似乎不是ASP.NET MVC的奇怪行为,而只是MvcMiniProfiler的标准行为。目前,我正在检查...

编辑:是的,ASP.NET MVC没问题,它只是MvcMiniProfiler的default configuration,仅忽略以下路径:"/mini-profiler-", "/content/", "/scripts/", "/favicon.ico"。这些默认值可以轻松扩展:

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

有时候,在使用某些东西之前先阅读文档是一个好主意;)

最佳答案

正如您在更新中指出的那样,这似乎是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

据推测,当您通过Cassini提供图像时,这些图像从未被缓存过,因为Cassini当时很糟糕(例如,将png文件作为application/octet-stream传递),但是MvcMiniProfiler手动从您的 View 中隐藏了该问题。

关于asp.net-mvc - 而且,ASP.NET MVC Content文件夹的神奇之处是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8164728/

相关文章:

c# - 无法从列表中删除项目

c# - 如何为多个分部 View 重用一个 Controller ?

java - Spring @Cachable : Not working on methods with parameters

caching - 另一个 CUDA 纹理内存线程。 (为什么 Fermi 上的纹理内存应该更快?)

asp.net-mvc - 如何在Asp.net MVC Web Api中创建Ror风格的Restful路由

c# - ASP.NET MVC 重定向到 Action 重定向循环

jquery - ASP.NET MVC 3 - ViewModel 和刷新 - 问题

performance - Google 的新 mod_pagespeed 是否只是为不知道如何正确做事的网站管理员提供的另一种工具?

c++ - 重构算法

asp.net-mvc - ASP.NET MVC4 路由 - 到同一位置的多个路由