HttpRequest.Filter プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > HttpRequest.Filter プロパティの意味・解説 

HttpRequest.Filter プロパティ

現在の入力ストリーム読み取るときに使用するフィルタ取得または設定します

名前空間: System.Web
アセンブリ: System.Web (system.web.dll 内)
構文構文

例外例外
例外種類条件

HttpException

指定されStream無効です。

使用例使用例

InputStream のフィルタ処理をする新し2 つクラスQQQ1QQQ2作成するコード例次に示します作成した 2 つクラスは、ASP.NET アプリケーションディレクトリの Global.asax ファイル内に置き、アプリケーション内のすべての aspx ページすべての入力フィルタ処理されるようにします。

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

<script runat=server>
' This example is meant to be added to a Global.asax file.

Sub Application_BeginRequest()
   Request.Filter = New QQQ1(Request.Filter)
   Request.Filter = New QQQ2(Request.Filter)
End Sub

' The class QQQ1 changes all lower case alpha chars to upper case.
Public Class QQQ1
   Inherits Stream

   Private _sink As Stream

   Public Sub New(sink As
 Stream)
      _sink = sink
   End Sub

   ' All MustOverride interface members must be included.
   Public Overrides ReadOnly
 Property CanRead() As Boolean
      Get 
         Return True
      End Get
   End Property

   Public Overrides ReadOnly
 Property CanSeek() As Boolean
      Get
         Return False
      End Get
   End Property

   Public Overrides ReadOnly
 Property CanWrite() As Boolean
      Get
         Return False
      End Get
   End Property

   Public Overrides ReadOnly
 Property Length() As Long
      Get
         Return _sink.Length
      End Get
   End Property

   Public Overrides Property
 Position() As Long
      Get
         Return _sink.Position
      End Get
      Set 
         Throw New NotSupportedException()
      End Set
   End Property

   Public Overrides Function
 Read(ByVal buffer() As Byte,
 ByVal offset As Integer, ByVal count As Integer) As
 Integer
      Dim c As Integer =
 _sink.Read(buffer, offset, count)
      Dim i As Integer
      For i = 0 To count - 1
         If buffer(offset+i) >= Asc("a")
 And buffer(offset+i) <= Asc("z")
 Then
            buffer(offset+i) = buffer(offset+i) - (Asc("a")-Asc("A"))
         End If
      Next i
      Return c
   End Function

   Public Overrides Function
 Seek(ByVal offset As Long,
 ByVal direction As System.IO.SeekOrigin) As Long
        Throw New NotSupportedException()
   End Function

   Public Overrides Sub
 SetLength(ByVal length As Long)
      Throw New NotSupportedException()
   End Sub

   Public Overrides Sub
 Close()
      _sink.Close()
   End Sub

   Public Overrides Sub
 Flush()
      _sink.Flush()
   End Sub

   Public Overrides Sub
 Write(ByVal buffer() As Byte,
 ByVal offset As Integer, ByVal count As Integer)
      Throw New NotSupportedException()
   End Sub
End Class


' The class QQQ2 changes all E characters to asterisks.
class QQQ2 
   Inherits Stream
    
   Private _sink As Stream

   Public Sub New(sink As
 Stream)
      _sink = sink
   End Sub

   ' All MustOverride interface members must be included.
   Public Overrides ReadOnly
 Property CanRead() As Boolean
      Get  
         Return true
      End Get
   End Property

   Public Overrides ReadOnly
 Property CanSeek() As Boolean
      Get
         Return False
      End Get
   End Property

   Public Overrides ReadOnly
 Property CanWrite() As Boolean
      Get 
         Return False
      End Get
   End Property

   Public Overrides ReadOnly
 Property Length() As Long
      Get
         Return _sink.Length
      End Get
   End Property

   Public Overrides Property
 Position() As Long
      Get
         Return _sink.Position
      End Get  
      Set 
         Throw New NotSupportedException()
      End Set
   End Property

   Public Overrides Function
 Read(ByVal buffer() As Byte,
 ByVal offset As Integer, ByVal count As Integer) As
 Integer
      Dim c As Integer =
 _sink.Read(buffer, offset, count)
      Dim i As Integer
      For i = 0 To count-1
         If buffer(i) = Asc("E")
 Then
            buffer(i) = Asc("*")
         End If
      Next i
      Return c
   End Function

   Public Overrides Function
 Seek(ByVal offset As Long,
 ByVal direction As System.IO.SeekOrigin) As Long
      Throw New NotSupportedException()
   End Function

   Public Overrides Sub
 SetLength(length As Long)
      Throw New NotSupportedException()
   End Sub

   Public Overrides Sub
 Close()
      _sink.Close()
   End Sub

   Public Overrides Sub
 Flush()
      _sink.Flush()
   End Sub

   Public Overrides Sub
 Write(ByVal buffer() As Byte,
 ByVal offset As Integer, ByVal count As Integer)
      Throw New NotSupportedException()
   End Sub
End Class


'____________________________________________________________________

' 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 = VB %>
'<%@ IMPORT namespace="System.IO" %>

'<html>
'<Script runat=server>

'   Sub Page_Load()
'      Dim str As Stream, strmContents As String
'      Dim counter, strLen As Integer
 
      ' Create a Stream object.
'      str = Request.InputStream

      ' Find number of bytes in stream.
'      strLen = CInt(str.Length)

      ' Create a byte array.
'      Dim strArr(strLen) As Byte 

      ' Read stream into byte array.
'      str.Read(strArr,0,strLen) 
 
      ' Convert byte array to a text string.
'      For counter = 0 To strLen-1
'         strmContents = strmContents & Chr(strArr(counter))
'      Next counter

'      Response.Write("Contents of Filtered InputStream: "
 & strmContents)
'   End Sub

'</Script>
'</html>

</script>
<%@ Page language="c#" %>
<%@ 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() 
{
   Request.Filter = new QQQ1(Request.Filter);
   Request.Filter = new QQQ2(Request.Filter);
}

class QQQ1 : Stream
{
    private Stream _sink;

    public QQQ1(Stream sink)
    {
        _sink = sink;
    }

    public override bool CanRead
    {
        get { return true;
 }
    }

    public override bool CanSeek
    {
        get { return false;
 }
    }

    public override bool CanWrite
    {
        get { return false;
 }
    }

    public override long Length
    {
        get { return _sink.Length; }
    }

    public override long Position
    {
        get { return _sink.Position; }
        set { throw new NotSupportedException();
 }
    }

    public override int Read(byte[] 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;
    }

    public override long Seek(long offset, System.IO.SeekOrigin
 direction)
    {
        throw new NotSupportedException();
    }

    public override void SetLength(long length)
    {
        throw new NotSupportedException();
    }

    public override void Close()
    {
        _sink.Close();
    }

    public override void Flush()
    {
        _sink.Flush();
    }

    public override void Write(byte[] buffer,
 int offset, int count)
    {
    throw new NotSupportedException();
    }
}

class QQQ2 : Stream
{
    private Stream _sink;

    public QQQ2(Stream sink)
    {
        _sink = sink;
    }

    public override bool CanRead
    {
        get { return true;
 }
    }

    public override bool CanSeek
    {
        get { return false;
 }
    }

    public override bool CanWrite
    {
        get { return false;
 }
    }

    public override long Length
    {
        get { return _sink.Length; }
    }

    public override long Position
    {
        get { return _sink.Position; }
        set { throw new NotSupportedException();
 }
    }

    public override int Read(byte[] 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] = (byte)'*';
            else if (buffer[i] == 'e')
                buffer[i] = (byte)'#';
        }
        return c;
    }

    public override long Seek(long offset, System.IO.SeekOrigin
 direction)
    {
        throw new NotSupportedException();
    }

    public override void SetLength(long length)
    {
        throw new NotSupportedException();
    }

    public override void Close()
    {
        _sink.Close();
    }

    public override void Flush()
    {
        _sink.Flush();
    }

    public override void Write(byte[] buffer,
 int offset, int count)
    {
    throw new NotSupportedException();
    }
}


/*____________________________________________________________________

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 = C# %>
<%@ IMPORT namespace="System.IO" %>

<html>
<Script runat=server>
   void Page_Load()
   {
 
      // Create a Stream object to capture entire InputStream from browser.
      Stream str = Request.InputStream;
   
      // Find number of bytes in stream.
      int strLen = (int)str.Length;

      // Create a byte array to hold stream.
      byte[] bArr = new byte[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 + (Char)bArr[i];
     
      // Display filtered stream in browser.
      Response.Write("Contents of Filtered InputStream: <br>" + strmContents);
   }
______________________________________________________________________*/

</script>
<%@ 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>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からHttpRequest.Filter プロパティを検索した結果を表示しています。
Weblioに収録されているすべての辞書からHttpRequest.Filter プロパティを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からHttpRequest.Filter プロパティ を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

HttpRequest.Filter プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



HttpRequest.Filter プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS