public override void OnActionExecuting(ActionExecutingContext filterContext) { var request = filterContext.RequestContext.HttpContext.Request; var response = filterContext.RequestContext.HttpContext.Response; //Format the request url without querystring var urlString = request.Url.ToString(); if (!string.IsNullOrEmpty(request.Url.Query)) { urlString = urlString.Replace(request.Url.Query, ""); } var url = new Uri(urlString); var webres = new WebResourceInfo(url); if (webres.IsFile) { var noneMatch = request.Headers["If-None-Match"]; var isNotMatch = true; if (!string.IsNullOrEmpty(noneMatch)) { var service = DependencyResolver.Current.GetService <INetDriveService>(); var file = service.MapPath(url); var etagHashed = GetEtag(file); isNotMatch = !noneMatch.Equals(etagHashed); } var isExpried = !(request.Headers["If-Modified-Since"] != null && TimeSpan.FromTicks(DateTime.Now.Ticks - DateTime.Parse(request.Headers["If-Modified-Since"]).Ticks).Seconds < Duration); if (!isNotMatch && !isExpried) { try { response.Write(DateTime.Now); response.StatusCode = 304; response.Headers.Add("Content-Encoding", "gzip"); response.StatusDescription = "Not Modified"; } catch //(System.PlatformNotSupportedException e) { base.OnActionExecuting(filterContext); } } else { base.OnActionExecuting(filterContext); } } else { base.OnActionExecuting(filterContext); } }
public override void OnActionExecuting(ActionExecutingContext filterContext) { var request = filterContext.RequestContext.HttpContext.Request; var response = filterContext.RequestContext.HttpContext.Response; //Format the request url without querystring var urlString = request.Url.ToString(); if (!string.IsNullOrEmpty(request.Url.Query)) urlString = urlString.Replace(request.Url.Query, ""); var url = new Uri(urlString); var webres = new WebResourceInfo(url); if (webres.IsFile) { var noneMatch = request.Headers["If-None-Match"]; var isNotMatch =true; if (!string.IsNullOrEmpty(noneMatch)) { var service = DependencyResolver.Current.GetService<INetDriveService>(); var file = service.MapPath(url); var etagHashed = GetEtag(file); isNotMatch = !noneMatch.Equals(etagHashed); } var isExpried=!(request.Headers["If-Modified-Since"] != null && TimeSpan.FromTicks(DateTime.Now.Ticks - DateTime.Parse(request.Headers["If-Modified-Since"]).Ticks).Seconds < Duration); if (!isNotMatch && !isExpried) { try { response.Write(DateTime.Now); response.StatusCode = 304; response.Headers.Add("Content-Encoding", "gzip"); response.StatusDescription = "Not Modified"; } catch //(System.PlatformNotSupportedException e) { base.OnActionExecuting(filterContext); } } else { base.OnActionExecuting(filterContext); } } else base.OnActionExecuting(filterContext); }