public override void OnResultExecuting(ResultExecutingContext filterContext)
        {
            // Should we hook the response?
            string cacheKey = filterContext.HttpContext.Items[_itemsCacheKey] as string;

            if (cacheKey != null)
            {
                TextWriter          originalWriter = filterContext.HttpContext.Response.Output;
                WrappedStringWriter newWriter      = new WrappedStringWriter(originalWriter);
                filterContext.HttpContext.Response.Output = newWriter;
            }
        }
        public override void OnResultExecuted(ResultExecutedContext filterContext)
        {
            string cacheKey = filterContext.HttpContext.Items[_itemsCacheKey] as string;

            if (cacheKey == null)
            {
                return; // nothing to do
            }

            // We know that the current writer is our special writer, so pop it
            WrappedStringWriter newWriter = (WrappedStringWriter)filterContext.HttpContext.Response.Output;

            filterContext.HttpContext.Response.Output = newWriter.OriginalWriter;
            string capturedText = newWriter.ToString();

            // dump the text to the output
            filterContext.HttpContext.Response.Write(capturedText);

            // save to cache
            if (filterContext.Exception == null)
            {
                SetCacheItem(filterContext.HttpContext, cacheKey, capturedText);
            }
        }
예제 #3
0
 public override void OnResultExecuting(ResultExecutingContext filterContext)
 {
     // Should we hook the response?
     string cacheKey = filterContext.HttpContext.Items[_itemsCacheKey] as string;
     if (cacheKey != null) {
         TextWriter originalWriter = filterContext.HttpContext.Response.Output;
         WrappedStringWriter newWriter = new WrappedStringWriter(originalWriter);
         filterContext.HttpContext.Response.Output = newWriter;
     }
 }