Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc ASP.NET MVC ySlow为动态服务的脚本添加过期标头_Asp.net Mvc_Yslow_Controller Action_Expires Header - Fatal编程技术网

Asp.net mvc ASP.NET MVC ySlow为动态服务的脚本添加过期标头

Asp.net mvc ASP.NET MVC ySlow为动态服务的脚本添加过期标头,asp.net-mvc,yslow,controller-action,expires-header,Asp.net Mvc,Yslow,Controller Action,Expires Header,我为Javascript vai提供的控制器方法如下所示: [OutputCache(Duration = 120)] [Compress] public ActionResult JavascriptFile(String scriptName) { string content; if (HttpContext.IsDebuggingEnabled) { content = ReadApplicationScript(string.Format

我为Javascript vai提供的控制器方法如下所示:

  [OutputCache(Duration = 120)]
  [Compress]
  public ActionResult JavascriptFile(String scriptName) {
     string content;
     if (HttpContext.IsDebuggingEnabled) {
        content = ReadApplicationScript(string.Format("~/scripts/{0}", scriptName));
        return Content(content, "application/javascript");
     }
     else {
        content = ReadApplicationScript(string.Format("~/scripts/Built/{0}", scriptName));
        return Content(content, "application/javascript");
     }
  }
var cacheName = "someName";
var value = HttpRuntime.Cache.Get(cacheName) as ContentResult;

            if (value == null)
            {                
                var contentResult = ReadApplicationScript(string.Format("~/scripts/{0}",scriptName));
                System.Web.HttpContext.Current.Cache.Insert(cacheName, contentResult );
                return contentResult;
            }

            return value;
Compress
属性来自


当我运行ySlow时,我在“添加过期标题”上得到了F级。如何添加这些内容?

在system.webServer内部添加以下内容

<staticContent>
      <clientCache cacheControlMode="UseExpires"
         httpExpires="Tue, 19 Jan 2038 03:14:07 GMT" />
    </staticContent>

我已经有了这个标签,我认为问题在于,因为我动态地为脚本提供服务,所以它不是静态内容,所以这不适用。请尝试按照给定的方式将内容添加到缓存中。我没有测试代码。@DhavalPanchal,您可以使用Web.config中system.webServer部分下的第一块代码。如果您使用的是MVC,则可以使用第二块代码创建控制器操作以返回内容结果。希望这有帮助。我正在使用ASP.Net,并且已经在web.config中添加了块。它适用于我网站的静态内容,但不适用于从第三方脚本添加的引用,如我的域是:www.abc.com,脚本引用是从www.xyz.com加载的