System.Web 名前空間


.NET Framework クラス ライブラリ
HttpResponse クラス

更新 : 2007 年 11 月

ASP.NET 操作からの HTTP 応答情報をカプセル化します。

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

構文

Visual Basic (宣言)
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class HttpResponse
Visual Basic (使用法)
Dim instance As HttpResponse
C#
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public sealed class HttpResponse
Visual C++
[AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)]
public ref class HttpResponse sealed
J#
/** @attribute AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal) */
public final class HttpResponse
JScript
public final class HttpResponse
解説

HttpResponse クラスのメソッドとプロパティは、HttpApplicationHttpContextPageUserControl の各クラスの Response プロパティによって公開されます。

HttpResponse クラスの次のメソッドは、ポストバックの状況でのみサポートされ、非同期ポストバックの状況ではサポートされません。

部分ページ更新は、ポストバックを使用してページ全体を更新する代わりに、UpdatePanel コントロールを使用してページの選択された領域を更新するときに有効になります。詳細については、「UpdatePanel コントロールの概要」および「部分ページ レンダリングの概要」を参照してください。

HttpResponse は、.NET Framework version 3.5 で導入されました。詳細については、「.NET Framework 3.5 のアーキテクチャ」を参照してください。

TopicLocation
方法 : ASP.NET Web ページ間で値をやり取りするASP .NET Web アプリケーションの作成
方法 : ASP.NET Web ページ間で値をやり取りするVisual Studio ASP .NET での Web アプリケーションの作成
方法 : ASP.NET Web ページ間の値を渡すdv_vwdcon

ページが要求されたときに 3 つの重なり合う四角形を描画する例を次に示します。まず ContentType プロパティを image/jpeg に設定し、ページ全体を JPEG イメージとして表示します。次に、Clear メソッドを呼び出し、この応答で無関係の内容が送信されないようにします。続いて、BufferOutput プロパティを true に設定し、要求元のクライアントに送信される前にページの処理が完了するようにします。さらに、四角形の描画に使用する 2 つのオブジェクトである Bitmap オブジェクトと Graphics オブジェクトを作成します。このページで作成される変数は、四角形の描画に使用する座標と、最も大きい四角形の内部に表示される文字列です。

3 つの四角形とその内部に表示される文字列が描画されると、BitmapOutputStream プロパティに関連付けられている Stream オブジェクトに保存され、形式が JPEG に設定されます。次に、Dispose メソッドと Dispose メソッドが呼び出され、2 つの描画オブジェクトによって使用されていたリソースが解放されます。最後に、Flush メソッドが呼び出され、バッファされた応答が要求元のクライアントに送信されます。

Visual Basic
<%@ Page Language="VB" %>
<%@ import Namespace="System.Drawing" %>
<%@ import Namespace="System.Drawing.Imaging" %>
<%@ import Namespace="System.Drawing.Drawing2D" %>
<!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(sender As Object, e As EventArgs)
      ' Set the page's content type to JPEG files
      ' and clear all response headers.
      Response.ContentType = "image/jpeg"
      Response.Clear()

      ' Buffer response so that page is sent
      ' after processing is complete.
      Response.BufferOutput = True

      ' Create a font style.
      Dim rectangleFont As New Font( _
          "Arial", 10, FontStyle.Bold)

      ' Create integer variables.
      Dim height As Integer = 100
      Dim width As Integer = 200

      ' Create a random number generator and create
      ' variable values based on it.
      Dim r As New Random()
      Dim x As Integer = r.Next(75)
      Dim a As Integer = r.Next(155)
      Dim x1 As Integer = r.Next(100)

      ' Create a bitmap and use it to create a
      ' Graphics object.
      Dim bmp As New Bitmap( _
          width, height, PixelFormat.Format24bppRgb)
      Dim g As Graphics = Graphics.FromImage(bmp)

      g.SmoothingMode = SmoothingMode.AntiAlias
      g.Clear(Color.LightGray)

      ' Use the Graphics object to draw three rectangles.
      g.DrawRectangle(Pens.White, 1, 1, width - 3, height - 3)
      g.DrawRectangle(Pens.Aquamarine, 2, 2, width - 3, height - 3)
      g.DrawRectangle(Pens.Black, 0, 0, width, height)

      ' Use the Graphics object to write a string
      ' on the rectangles.
      g.DrawString("ASP.NET Samples", rectangleFont, SystemBrushes.WindowText, New PointF(10, 40))

      ' Apply color to two of the rectangles.
      g.FillRectangle( _
          New SolidBrush( _
              Color.FromArgb(a, 255, 128, 255)), _
          x, 20, 100, 50)

      g.FillRectangle( _
          New LinearGradientBrush( _
              New Point(x, 10), _
              New Point(x1 + 75, 50 + 30), _
              Color.FromArgb(128, 0, 0, 128), _
              Color.FromArgb(255, 255, 255, 240)), _
          x1, 50, 75, 30)

      ' Save the bitmap to the response stream and
      ' convert it to JPEG format.
      bmp.Save(Response.OutputStream, ImageFormat.Jpeg)

      ' Release memory used by the Graphics object
      ' and the bitmap.
      g.Dispose()
      bmp.Dispose()

      ' Send the output to the client.
      Response.Flush()
   End Sub 'Page_Load

</script>
<html  >
<head>
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
    </form>
</body>
</html>
C#
<%@ Page Language="C#" %>
<%@ import Namespace="System.Drawing" %>
<%@ import Namespace="System.Drawing.Imaging" %>
<%@ import Namespace="System.Drawing.Drawing2D" %>

<!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)
    {
        // Set the page's content type to JPEG files
        // and clear all response headers.
        Response.ContentType = "image/jpeg";
        Response.Clear();

        // Buffer response so that page is sent
        // after processing is complete.
        Response.BufferOutput = true;

        // Create a font style.
        Font rectangleFont = new Font(
            "Arial", 10, FontStyle.Bold);

        // Create integer variables.
        int height = 100;
        int width = 200;

        // Create a random number generator and create
        // variable values based on it.
        Random r = new Random();
        int x = r.Next(75);
        int a = r.Next(155);
        int x1 = r.Next(100);

        // Create a bitmap and use it to create a
        // Graphics object.
        Bitmap bmp = new Bitmap(
            width, height, PixelFormat.Format24bppRgb);
        Graphics g = Graphics.FromImage(bmp);

        g.SmoothingMode = SmoothingMode.AntiAlias;
        g.Clear(Color.LightGray);

        // Use the Graphics object to draw three rectangles.
        g.DrawRectangle(Pens.White, 1, 1, width-3, height-3);
        g.DrawRectangle(Pens.Aquamarine, 2, 2, width-3, height-3);
        g.DrawRectangle(Pens.Black, 0, 0, width, height);

        // Use the Graphics object to write a string
        // on the rectangles.
        g.DrawString(
            "ASP.NET Samples", rectangleFont,
            SystemBrushes.WindowText, new PointF(10, 40));

        // Apply color to two of the rectangles.
        g.FillRectangle(
            new SolidBrush(
                Color.FromArgb(a, 255, 128, 255)),
            x, 20, 100, 50);

        g.FillRectangle(
            new LinearGradientBrush(
                new Point(x, 10),
                new Point(x1 + 75, 50 + 30),
                Color.FromArgb(128, 0, 0, 128),
                Color.FromArgb(255, 255, 255, 240)),
            x1, 50, 75, 30);

        // Save the bitmap to the response stream and
        // convert it to JPEG format.
        bmp.Save(Response.OutputStream, ImageFormat.Jpeg);

        // Release memory used by the Graphics object
        // and the bitmap.
        g.Dispose();
        bmp.Dispose();

        // Send the output to the client.
        Response.Flush();
    }

</script>
<html  >
<head>
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
    </form>
</body>
</html>
アクセス許可

継承階層

System..::.Object
  System.Web..::.HttpResponse
スレッド セーフ

この型のすべてのパブリック static (Visual Basic では Shared) メンバは、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォーム

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

.NET Framework および .NET Compact Framework では、各プラットフォームのすべてのバージョンはサポートしていません。サポートされているバージョンについては、「.NET Framework システム要件」を参照してください。

バージョン情報

.NET Framework

サポート対象 : 3.5、3.0、2.0、1.1、1.0
参照

参照

タグ :


Page view tracker