伝送する前に HTTP エンティティ本体を変更するために使用される、ラッピング フィルタ オブジェクトを取得または設定します。
名前空間: System.Web
アセンブリ: System.Web (system.web.dll 内)
構文
'宣言
Public Property Filter As Stream
'使用
Dim instance As HttpResponse
Dim value As Stream
value = instance.Filter
instance.Filter = value
public Stream Filter { get; set; }
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)
適用できません。
プロパティ値
出力フィルタとして機能する Stream。
例外
例外の種類 | 条件 |
---|---|
このエンティティではフィルタ処理を実行できません。 |
解説
Stream オブジェクトを作成し、Filter プロパティを Stream オブジェクトに設定すると、Write によって送信されたすべての HTTP 出力は、フィルタをとおして渡されます。
使用例
次のコード例の ASP.NET ページは、Filter プロパティを UpperCaseFilter
クラスの新しいインスタンスに設定します。このクラスは、渡されるすべてのテキストを大文字に変換するカスタム Stream クラスです。要求に関する情報はテキスト ファイルに保存され、次に Filter プロパティが設定されます。応答フィルタが配置された後、MapPath メソッドが呼び出されて、TestFile.txt という名前のテキスト ファイルへの絶対パスが取得されます。このファイルは、応答のコンテンツのソースとして機能します。続いて、新しい StreamReader オブジェクトが作成されて、このテキスト ファイルが最初から最後まで読み取られます。さらに、Write メソッドが呼び出されて、ファイルの内容がページに表示されます。
<%@ 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 xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>HttpResponse.MapPath Example</title>
</head>
<body>
<form id="Form1" runat="server">
<asp:Label id="Message"
runat="server"/>
</form>
</body>
</html>
<%@ 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 xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>HttpResponse.MapPath Example</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Label id="Message"
runat="server"/>
</form>
</body>
</html>
<%@ 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 xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>ASP.NET Example</title>
</head>
<body>
<% get_Response().Write("This text will be rendered all uppercase." ); %>
</body>
</html>
プラットフォーム
Windows 98,Windows Server 2000 SP4,Windows CE,Windows Millennium Edition,Windows Mobile for Pocket PC,Windows Mobile for Smartphone,Windows Server 2003,Windows XP Media Center Edition,Windows XP Professional x64 Edition,Windows XP SP2,Windows XP Starter Edition
Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。
バージョン情報
.NET Framework
サポート対象 : 3.0,2.0,1.1,1.0