0

I try to intercept textraw from my Custom OutputCacheProvider CacheEntry Buffer.

when I use cacheEntry.ResponseElements.First() I get the Half of my html page, but when I try to concat all chunck, I've get a crapy response (looks like binary serialized data). How can I do someting like :

IOutputCacheEntry cacheEntry = cachedItem.Item as IOutputCacheEntry;
StringBuilder textResponse = new StringBuilder();
                foreach (var responseRaw in cacheEntry.ResponseElements.Where(s=>!(s is FileResponseElement )))
                {

                    Byte[] bytes = (Byte[])responseRaw.GetType().GetField("_buffer",
                        BindingFlags.NonPublic |
                        BindingFlags.Instance).GetValue(responseRaw);
                    textResponse.Append(Encoding.Default.GetString(bytes));    
                }

edit : I tried to concat all byte[] before "Stringify" them, and I tried with UTF-8 encoding.

Christophe Debove
  • 6,088
  • 20
  • 73
  • 124

1 Answers1

0

Are you using the right encoding? Encoding.Default returns the encoding for the current system ANSI codepage. This might not work if you're using UTF-8 or some other encoding. You should check the Content-type: header to identify the correct encoding to use.

Dai
  • 141,631
  • 28
  • 261
  • 374