Use multiple response filters in ASP.NET
is there any way to use multiple response filters in ASP.NET?
HttpContext.Current.Response.Filte开发者_Python百科r = MyFilter1
HttpContext.Current.Response.Filter = MyFilter2
This code is clear, can't work. It overrides the current filter with the new instance.
So, what are your best practice for this scenario.
Thank and best regards.
A filter is a Stream that writes to another Stream. Usually you construct a filter like this:
response.Filter = new MyStream(response.Filter);
To use multiple filters, you do the same:
response.Filter = new FirstFilterStream(response.Filter);
response.Filter = new SecondFilterStream(response.Filter);
Only a single response filter can be applied, so you need to aggregate all the work in this filter. Here's an example how this could be achieved:
Response.Filter = new TrimStream(new CompressStream(Response.Filter));
This way you can combine multiple streams.
精彩评论