HttpResponse.Filter 속성

정의

전송 전에 HTTP 엔터티 본문을 수정하는 데 사용되는 래핑 필터 개체를 가져오거나 설정합니다.

public:
 property System::IO::Stream ^ Filter { System::IO::Stream ^ get(); void set(System::IO::Stream ^ value); };
public System.IO.Stream Filter { get; set; }
member this.Filter : System.IO.Stream with get, set
Public Property Filter As Stream

속성 값

Stream

출력 필터 역할을 하는 Stream 개체입니다.

예외

해당 엔터티에 필터링을 사용할 수 없는 경우

예제

다음 예제는 클래스의 UpperCaseFilter 새 인스턴스로 속성을 설정 Filter 하는 ASP.NET 페이지, 대문자로 전달 하는 모든 텍스트를 변환 하는 사용자 지정 Stream 클래스입니다. 요청에 대한 정보가 텍스트 파일에 저장되고 속성이 Filter 설정됩니다. 응답 필터가 준비되면 코드는 메서드를 호출 MapPath 하여 응답 내용의 원본 역할을 하는 텍스트 TestFile.txt 파일의 절대 경로를 가져옵니다. 그런 다음 코드는 텍스트 파일을 처음부터 끝까지 읽는 새 StreamReader 개체를 만든 다음 메서드를 Write 호출하여 페이지에 파일의 내용을 표시합니다.

<%@ 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="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>

설명

개체를 Stream 만들고 속성을 개체로 Stream 설정 Filter 하면 전송된 Write 모든 HTTP 출력이 필터를 통과합니다.

적용 대상