Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
HttpResponse Class
 Filter Property
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
HttpResponse..::.Filter Property

Updated: November 2007

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)

Visual Basic (Declaration)
Public Property Filter As Stream
Visual Basic (Usage)
Dim instance As HttpResponse
Dim value As Stream

value = instance.Filter

instance.Filter = value
C#
public Stream Filter { get; set; }
Visual C++
public:
property Stream^ Filter {
    Stream^ get ();
    void set (Stream^ value);
}
J#
/** @property */
public Stream get_Filter()
/** @property */
public  void set_Filter(Stream value)
JScript
public function get Filter () : Stream
public function set Filter (value : Stream)

Property Value

Type: System.IO..::.Stream

The Stream object that acts as the output filter.

ExceptionCondition
HttpException

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.

Visual Basic
<%@ Page Language="VB" Debug="true"%>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="Samples.AspNet.VB.Controls" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

    ' 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.
    Dim fullpath As String = Request.MapPath("~\\TestFile.txt")

    Try

      Dim sr As StreamReader = New StreamReader(fullpath)

      Do While sr.Peek() >= 0
        Response.Write(Convert.ToChar(sr.Read()))
      Loop
      sr.Close()
      Message.Text = "Reading the file was successful."

    Catch ex As Exception

      Message.Text = "The process failed."

    End Try


  End Sub

</script>
<html  >
  <head>
    <title>HttpResponse.MapPath Example</title>
  </head>
  <body>
    <form id="Form1" runat="server">

      <asp:Label id="Message" 
                 runat="server"/>

    </form>
  </body>
</html>

C#
<%@ Page Language="C#" %>
<%@ Import Namespace="System.IO" %>
<%@ import Namespace="Samples.AspNet.CS.Controls"  %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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");

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

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

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

      <asp:Label id="Message" 
                 runat="server"/>

    </form>
  </body>
</html>

J#
<%@ Page Language="VJ#" %>
<%@ import Namespace="Samples.AspNet" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

    private void Page_Load(Object sender, EventArgs e)
    {

       // Filter the text to be rendered as all uppercase.
       get_Response().set_Filter(new UpperCaseFilterStream(get_Response().
           get_Filter()));

    } //Page_Load

</script>
<html  >
<head>
    <title>ASP.NET Example</title>
</head>
<body>
    <% get_Response().Write("This text will be rendered all uppercase." ); %>
</body>
</html>

Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker