HttpResponse.Filter Property


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Gets or sets a wrapping filter object that is used to modify the HTTP entity body before transmission.

Namespace:   System.Web
Assembly:  System.Web (in System.Web.dll)

public Stream Filter { get; set; }

Property Value

Type: System.IO.Stream

The Stream object that acts as the output filter.

Exception Condition

Filtering is not allowed with the entity.

When you create a Stream object and set the Filter property to the Stream object, all HTTP output sent by Write passes through the filter.

The following example is an ASP.NET page that sets the Filter property to a new instance of the UpperCaseFilter class, a custom Stream class that converts all text that passes through it to uppercase. The information about the request is saved to a text file, and then the Filter property is set. After the response filter is in place, the code calls the MapPath method to get the absolute path to a text file named TestFile.txt that serves as the source for the content of the response. The code then creates a new StreamReader object to read the text file from beginning to end, and then calls the Write method to display the content of the file on the page.

<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO" %>
<%@ import Namespace="Samples.AspNet.CS.Controls"  %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<script runat="server">

    private void Page_Load(object sender, EventArgs e)

      // Filter the text to be rendered as all uppercase.
      Response.Filter = new UpperCaseFilterStream(Response.Filter);

      // Convert a virtual path to a fully qualified physical path.
      string fullpath = Request.MapPath("~\\TestFile.txt");

        // Read the contents of the file using a StreamReader.
        using (StreamReader sr = new StreamReader(fullpath))
        while (sr.Peek() >= 0)
        Message.Text = "Reading the file was successful.";

      catch (Exception ex)
        Message.Text = "The process failed.";

<html xmlns="" >
    <title>HttpResponse.MapPath Example</title>
    <form id="form1" runat="server">

      <asp:Label id="Message" 


.NET Framework
Available since 1.1
Return to top