S
Salim Afsar
Hi,
I'm trying to compress all requests.
When client send a request, I will compress the response and send it to
client.
For this purpose I get Response.Filter stream and try to read this
stream.(Because I need a string of response)
Here is my code:
protected void Application_PreSendRequestContent(object sender, EventArgs e)
{
Stream sTemp = Response.Filter;
sTemp = new TrimStream(sTemp);
StreamReader sr = new StreamReader(sTemp);
string strHTML = sr.ReadToEnd();
sr.Close();
}
I get an error on the 4th line(string strHTML = sr.ReadToEnd();
Here is my TempStream class.
public class TempStream : Stream
{
private Stream stream;
public TempStream(Stream stm)
{
stream = stm;
}
public override void Write(byte[] buffer, int offset, int count)
{
}
public override int Read(byte[] buffer, int offset, int count)
{
return stream.Read(buffer, offset, count);
}
public override bool CanRead
{
get { return true; }
}
public override bool CanSeek
{ get { return true; } }
public override bool CanWrite
{ get { return true; } }
public override long Length
{ get { throw new NotSupportedException(); } }
public override long Position
{
get { throw new NotSupportedException(); }
set { throw new NotSupportedException(); }
}
public override void Flush()
{
stream.Flush();
}
public override long Seek(long offset, SeekOrigin origin)
{
throw new NotSupportedException();
}
public override void SetLength(long value)
{
throw new NotSupportedException();
}
}
Any help will be appreciated kindly.
Thanks
I'm trying to compress all requests.
When client send a request, I will compress the response and send it to
client.
For this purpose I get Response.Filter stream and try to read this
stream.(Because I need a string of response)
Here is my code:
protected void Application_PreSendRequestContent(object sender, EventArgs e)
{
Stream sTemp = Response.Filter;
sTemp = new TrimStream(sTemp);
StreamReader sr = new StreamReader(sTemp);
string strHTML = sr.ReadToEnd();
sr.Close();
}
I get an error on the 4th line(string strHTML = sr.ReadToEnd();
Here is my TempStream class.
public class TempStream : Stream
{
private Stream stream;
public TempStream(Stream stm)
{
stream = stm;
}
public override void Write(byte[] buffer, int offset, int count)
{
}
public override int Read(byte[] buffer, int offset, int count)
{
return stream.Read(buffer, offset, count);
}
public override bool CanRead
{
get { return true; }
}
public override bool CanSeek
{ get { return true; } }
public override bool CanWrite
{ get { return true; } }
public override long Length
{ get { throw new NotSupportedException(); } }
public override long Position
{
get { throw new NotSupportedException(); }
set { throw new NotSupportedException(); }
}
public override void Flush()
{
stream.Flush();
}
public override long Seek(long offset, SeekOrigin origin)
{
throw new NotSupportedException();
}
public override void SetLength(long value)
{
throw new NotSupportedException();
}
}
Any help will be appreciated kindly.
Thanks