Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.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
C# 压缩/缓存和请求对象不能一起工作ASP.NET_C#_Asp.net_Asp.net Mvc_Razor_Asp.net Mvc 5 - Fatal编程技术网

C# 压缩/缓存和请求对象不能一起工作ASP.NET

C# 压缩/缓存和请求对象不能一起工作ASP.NET,c#,asp.net,asp.net-mvc,razor,asp.net-mvc-5,C#,Asp.net,Asp.net Mvc,Razor,Asp.net Mvc 5,我对ASP.NET应用程序有一个小问题 我已经配置了一个ViewBag变量,以便(使用razor)向我的视图发送带有querystring的下一页链接,但启用此属性时: public class CompressAttribute : System.Web.Mvc.ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) {

我对ASP.NET应用程序有一个小问题

我已经配置了一个ViewBag变量,以便(使用razor)向我的视图发送带有querystring的下一页链接,但启用此属性时:

public class CompressAttribute : System.Web.Mvc.ActionFilterAttribute
  {
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
      #region Cache
      HttpContext.Current.Response.Cache.SetExpires(DateTime.Now.AddDays(1));
      HttpContext.Current.Response.Cache.SetValidUntilExpires(true);
      HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Public);
      HttpContext.Current.Response.Cache.VaryByHeaders["Accept-Encoding"] = true;
      #endregion
      #region Compression
      var encodingsAccepted = filterContext.HttpContext.Request.Headers["Accept-Encoding"];
      if (string.IsNullOrEmpty(encodingsAccepted)) return;

      encodingsAccepted = encodingsAccepted.ToLowerInvariant();
      var response = filterContext.HttpContext.Response;

      if (encodingsAccepted.Contains("deflate"))
      {
        response.AppendHeader("Content-Encoding", "deflate");
        response.Filter = new DeflateStream(response.Filter, CompressionMode.Compress);
      }
      else if (encodingsAccepted.Contains("gzip"))
      {
        response.AppendHeader("Content-Encoding", "gzip");
        response.Filter = new GZipStream(response.Filter, CompressionMode.Compress);
      }
      #endregion
    }
  }
该网站不完全关注以下声明:

ViewBag.NextPageLink = "/" + culture + "/next/" + pageName + Request.Url.Query;
它只生成链接:/culture/next/pageName,但不包括查询字符串(它的标记为null)

我的CompressAttribute中有什么东西会导致这种情况吗?因为很明显,当禁用它时,重定向是有效的

编辑:


看来缓存是有原因的。当使用不同的查询重新加载页面时,服务器可能不会重新呈现此链接。

即使查询字符串已更改,服务器也会返回相同的缓存页面。 要告诉服务器改变每个查询字符串的缓存,请使用

例如:

HttpContext.Current.Response.Cache.VaryByParams["*"] = true; //* means all params

顺便说一句,您可能希望使用OutputCacheAttribute和IIS压缩,而不是自己滚动。

所有参数都是指url中设置的每个参数?还是询问串的每一把钥匙?因为我只需要重新加载querystring:)所有HTTP Get或Post参数ASP.NET。您可以使用以下格式告诉ASP.net仅根据特定参数进行更改:Response.Cache.VaryByParams[“Category”]=true//几天前我解决了我的问题。我使用它作为创建链接的函数的属性。谢谢