Export (0) Print
Expand All

HttpRequest.Filter Property

Gets or sets the filter to use when reading the current input stream.

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

public:
property Stream^ Filter {
	Stream^ get ();
	void set (Stream^ value);
}
/** @property */
public Stream get_Filter ()

/** @property */
public void set_Filter (Stream value)

public function get Filter () : Stream

public function set Filter (value : Stream)

Property Value

A Stream object to be used as the filter.

Exception typeCondition

HttpException

The specified Stream is invalid.

The following code example creates two new classes, QQQ1 and QQQ2 that filter the InputStream. Put the classes into the Global.asax file in an ASP.NET application's directory so that all input for all aspx pages in the application will be filtered.

No code example is currently available or this language may not be supported.

<%@ Page language="VJ#" %>
<%@ Import namespace="System.Text" %>
<%@ Import namespace="System.IO" %>

<script runat=server>
// This code is to be added to a Global.asax file.
public void Application_BeginRequest() 
{
    get_Request().set_Filter(new QQQ1(get_Request().get_Filter()));
    get_Request().set_Filter(new QQQ2(get_Request().get_Filter()));
} //Application_BeginRequest

class QQQ1 extends Stream
{
    private Stream _sink;
    
    public QQQ1(Stream sink) 
    {
        _sink = sink;
    } //QQQ1
   
    /** @property 
     */
    public boolean get_CanRead()
    {
        return true;
    } //get_CanRead
   
    /** @property 
     */
    public boolean get_CanSeek()
    {
        return false;
    } //get_CanSeek
   
    /** @property 
     */
    public boolean get_CanWrite()
    {
        return false;
    }//get_CanWrite
   
    /** @property 
     */
    public long get_Length()
    {
        return _sink.get_Length();
    } //get_Length
   
    /** @property
     */
    public long get_Position()
    {
        return _sink.get_Position();
    } //get_Position
   
    /** @property
     */
    public void set_Position (long value)
    {
        throw new NotSupportedException();
    } //set_Position
   
    public int Read(ubyte buffer[], int offset, int count) 
    {
        int c = _sink.Read(buffer, offset, count);
        for (int i=0;i < count;i++) {
            if ((buffer[offset + i]>='a')&& (buffer[offset + i] <='z')) {
                buffer[offset+i]-= ('a' - 'A');
            }
        }
        return c;
    } //Read
   
    public long Seek(long offset, System.IO.SeekOrigin direction) 
    {
        throw new NotSupportedException();
    } //Seek
   
    public void SetLength(long length)
    {
        throw new NotSupportedException();
    } //SetLength
   
    public void Close()
    {
        _sink.Close();
    } //Close
   
    public void Flush()
    {
        _sink.Flush();
    } //Flush
   
   public void Write(ubyte buffer[], int offset, int count)
   {
        throw new NotSupportedException();
   } //Write
} //QQQ1

class QQQ2 extends Stream
{
    private Stream _sink;
      
    public QQQ2(Stream sink)
    {
        _sink = sink;
    } //QQQ2
      
    /** @property 
     */
    public boolean get_CanRead()
    {
        return true;
    } //get_CanRead
   
    /** @property
     */
    public boolean get_CanSeek()
    {
        return false;
    } //get_CanSeek
   
    /** @property 
     */
    public boolean get_CanWrite()
    {
        return false;
    } //get_CanWrite
      
    /** @property 
     */
    public long get_Length()
    {
        return _sink.get_Length();
    } //get_Length
   
    /** @property
     */
    public long get_Position()
    {
        return _sink.get_Position();
    } //get_Position
    
    /** @property 
     */
    public void set_Position (long value)
    {
        throw new NotSupportedException();
    } //set_Position
      
    public int Read(ubyte buffer[], int offset, int count)
    {
        int c = _sink.Read(buffer, offset, count);
        for (int i=0;i < count;i++) {
            if (buffer[i] == 'E') {
                buffer[i] = (ubyte) '*';
            }
            else {
                if (buffer[i] == 'e') {
                    buffer[i]= (ubyte)'#';
                }
            }
        } 
        return c;
    } //Read
   
    public long Seek(long offset, System.IO.SeekOrigin direction) 
    {
        throw new NotSupportedException();
    } //Seek
   
    public void SetLength(long length) 
    {
        throw new NotSupportedException();
    } //SetLength
   
    public void Close() 
    {
        _sink.Close();
    } //Close
   
    public void Flush()
    {
        _sink.Flush();
    } //Flush
   
    public void Write(ubyte buffer[], int offset, int count) 
    {
        throw new NotSupportedException();
    } //Write
} //QQQ2

/*This ASP.NET page uses the request filter to modify all text sent by the 
browser in Request.InputStream. To test the filter, use this page to take
the POSTed output from a data entry page using a tag such as: 
<form method="POST" action="ThisTestPage.aspx" 

<%@ PAGE LANGUAGE = VJ# %>
<%@ IMPORT namespace="System.IO" %>

<html>
<Script runat=server>
    void Page_Load()
    {
        // Create a Stream object to capture entire InputStream from browser.
        Stream str = get_Request().get_InputStream();
        // Find number of bytes in stream.
        int strLen = (int)(str.get_Length());
        // Create a byte array to hold stream.
        ubyte bArr[] = new ubyte[strLen];
        // Read stream into byte array.
        str.Read(bArr, 0, strLen);
        // Convert byte array to a text string.
        String strmContents = "";
        for (int i = 0; i < strLen; i++) {
            strmContents = strmContents + (System.Char)(bArr.get_Item(i));
        }
        // Display filtered stream in browser.
        get_Response().Write("Contents of Filtered InputStream: <br>"
            + strmContents);
    } //Page_Load

______________________________________________________________________*/
</script>

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

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

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft