Export (0) Print
Expand All
0 out of 3 rated this helpful - Rate this topic

HttpResponse Class

Encapsulates HTTP-response information from an ASP.NET operation.

System.Object
  System.Web.HttpResponse

Namespace:  System.Web
Assembly:  System.Web (in System.Web.dll)
public sealed class HttpResponse

The HttpResponse type exposes the following members.

  NameDescription
Public methodHttpResponseInfrastructure. Initializes a new instance of the HttpResponse class.
Top
  NameDescription
Public propertyBufferGets or sets a value indicating whether to buffer output and send it after the complete response is finished processing.
Public propertyBufferOutputGets or sets a value indicating whether to buffer output and send it after the complete page is finished processing.
Public propertyCacheGets the caching policy (such as expiration time, privacy settings, and vary clauses) of a Web page.
Public propertyCacheControlGets or sets the Cache-Control HTTP header that matches one of the HttpCacheability enumeration values.
Public propertyCharsetGets or sets the HTTP character set of the output stream.
Public propertyContentEncodingGets or sets the HTTP character set of the output stream.
Public propertyContentTypeGets or sets the HTTP MIME type of the output stream.
Public propertyCookiesGets the response cookie collection.
Public propertyExpiresGets or sets the number of minutes before a page cached on a browser expires. If the user returns to the same page before it expires, the cached version is displayed. Expires is provided for compatibility with earlier versions of ASP.
Public propertyExpiresAbsoluteGets or sets the absolute date and time at which to remove cached information from the cache. ExpiresAbsolute is provided for compatibility with earlier versions of ASP.
Public propertyFilterGets or sets a wrapping filter object that is used to modify the HTTP entity body before transmission.
Public propertyHeaderEncodingGets or sets an Encoding object that represents the encoding for the current header output stream.
Public propertyHeadersGets the collection of response headers.
Public propertyIsClientConnectedGets a value indicating whether the client is still connected to the server.
Public propertyIsRequestBeingRedirectedGets a Boolean value indicating whether the client is being transferred to a new location.
Public propertyOutputEnables output of text to the outgoing HTTP response stream.
Public propertyOutputStreamEnables binary output to the outgoing HTTP content body.
Public propertyRedirectLocationGets or sets the value of the Http Location header.
Public propertyStatusSets the Status line that is returned to the client.
Public propertyStatusCodeGets or sets the HTTP status code of the output returned to the client.
Public propertyStatusDescriptionGets or sets the HTTP status string of the output returned to the client.
Public propertySubStatusCodeGets or sets a value qualifying the status code of the response.
Public propertySuppressContentGets or sets a value indicating whether to send HTTP content to the client.
Public propertyTrySkipIisCustomErrorsGets or sets a value that specifies whether IIS 7.0 custom errors are disabled.
Top
  NameDescription
Public methodAddCacheDependencyAssociates a set of cache dependencies with the response to facilitate invalidation of the response if it is stored in the output cache and the specified dependencies change.
Public methodAddCacheItemDependencies(ArrayList)Makes the validity of a cached response dependent on other items in the cache.
Public methodAddCacheItemDependencies(String[])Makes the validity of a cached item dependent on another item in the cache.
Public methodAddCacheItemDependencyMakes the validity of a cached response dependent on another item in the cache.
Public methodAddFileDependencies(ArrayList)Adds a group of file names to the collection of file names on which the current response is dependent.
Public methodAddFileDependencies(String[])Adds an array of file names to the collection of file names on which the current response is dependent.
Public methodAddFileDependencyAdds a single file name to the collection of file names on which the current response is dependent.
Public methodAddHeaderAdds an HTTP header to the output stream. AddHeader is provided for compatibility with earlier versions of ASP.
Public methodAppendCookieInfrastructure. Adds an HTTP cookie to the intrinsic cookie collection.
Public methodAppendHeaderAdds an HTTP header to the output stream.
Public methodAppendToLogAdds custom log information to the Internet Information Services (IIS) log file.
Public methodApplyAppPathModifierAdds a session ID to the virtual path if the session is using Cookieless session state and returns the combined path. If Cookieless session state is not used, ApplyAppPathModifier returns the original virtual path.
Public methodBinaryWriteWrites a string of binary characters to the HTTP output stream.
Public methodClearClears all content output from the buffer stream.
Public methodClearContentClears all content output from the buffer stream.
Public methodClearHeadersClears all headers from the buffer stream.
Public methodCloseCloses the socket connection to a client.
Public methodDisableKernelCacheDisables kernel caching for the current response.
Public methodEndSends all currently buffered output to the client, stops execution of the page, and raises the EndRequest event.
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodFlushSends all currently buffered output to the client.
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodPicsAppends a HTTP PICS-Label header to the output stream.
Public methodRedirect(String)Redirects a request to a new URL and specifies the new URL.
Public methodRedirect(String, Boolean)Redirects a client to a new URL. Specifies the new URL and whether execution of the current page should terminate.
Public methodRedirectPermanent(String)Performs a permanent redirection from the requested URL to the specified URL.
Public methodRedirectPermanent(String, Boolean)Performs a permanent redirection from the requested URL to the specified URL, and provides the option to complete the response.
Public methodRedirectToRoute(Object)Redirects a request to a new URL by using route parameter values.
Public methodRedirectToRoute(RouteValueDictionary)Redirects a request to a new URL by using route parameter values.
Public methodRedirectToRoute(String)Redirects a request to a new URL by using a route name.
Public methodRedirectToRoute(String, Object)Redirects a request to a new URL by using route parameter values and a route name.
Public methodRedirectToRoute(String, RouteValueDictionary)Redirects a request to a new URL by using route parameter values and a route name.
Public methodRedirectToRoutePermanent(Object)Performs a permanent redirection from a requested URL to a new URL by using route parameter values.
Public methodRedirectToRoutePermanent(RouteValueDictionary)Performs a permanent redirection from a requested URL to a new URL by using route parameter values.
Public methodRedirectToRoutePermanent(String)Performs a permanent redirection from a requested URL to a new URL by using a route name.
Public methodRedirectToRoutePermanent(String, Object)Performs a permanent redirection from a requested URL to a new URL by using the route parameter values and the name of the route that correspond to the new URL.
Public methodRedirectToRoutePermanent(String, RouteValueDictionary)Performs a permanent redirection from a requested URL to a new URL by using route parameter values and a route name.
Public methodStatic memberRemoveOutputCacheItem(String)Removes from the cache all cached items that are associated with the default output-cache provider. This method is static.
Public methodStatic memberRemoveOutputCacheItem(String, String)Uses the specified output-cache provider to remove all output-cache items that are associated with the specified path.
Public methodSetCookieInfrastructure. Updates an existing cookie in the cookie collection.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Public methodTransmitFile(String)Writes the specified file directly to an HTTP response output stream, without buffering it in memory.
Public methodTransmitFile(String, Int64, Int64)Writes the specified part of a file directly to an HTTP response output stream without buffering it in memory.
Public methodWrite(Char)Writes a character to an HTTP response output stream.
Public methodWrite(Object)Writes an Object to an HTTP response stream.
Public methodWrite(String)Writes a string to an HTTP response output stream.
Public methodWrite(Char[], Int32, Int32)Writes an array of characters to an HTTP response output stream.
Public methodWriteFile(String)Writes the contents of the specified file directly to an HTTP response output stream as a file block.
Public methodWriteFile(String, Boolean)Writes the contents of the specified file directly to an HTTP response output stream as a memory block.
Public methodWriteFile(IntPtr, Int64, Int64)Writes the specified file directly to an HTTP response output stream.
Public methodWriteFile(String, Int64, Int64)Writes the specified file directly to an HTTP response output stream.
Public methodWriteSubstitutionAllows insertion of response substitution blocks into the response, which allows dynamic generation of specified response regions for output cached responses.
Top

The methods and properties of the HttpResponse class are exposed through the Response property of the HttpApplication, HttpContext, Page, and UserControl classes.

The following methods of the HttpResponse class are supported only in postback scenarios and not in asynchronous postback scenarios:

Partial-page updates are enabled when you use UpdatePanel controls to update selected regions of a page instead of updating the whole page with a postback. For more information, see UpdatePanel Control Overview and Partial-Page Rendering Overview.

TopicLocation
How to: Pass Values Between ASP.NET Web PagesBuilding ASP .NET Web Applications
How to: Pass Values Between ASP.NET Web PagesBuilding ASP .NET Web Applications

The following example draws three overlapping rectangles when the page is requested. The code begins by setting the ContentType property to image/jpeg, so that the entire page will be rendered as a JPEG image. The code then calls the Clear method to ensure that no extraneous content is sent with this response. Next, the code sets the BufferOutput property to true so that the page is completely processed before it is sent to the requesting client. Two objects used to draw the rectangles are then created: a Bitmap and a Graphics object. The variables created in the page are used as coordinates to draw the rectangles and a string that appears inside the largest rectangle.

When the three rectangles and the string that appears inside them are drawn, the Bitmap is saved to the Stream object that is associated with the OutputStream property and its format is set to JPEG. The code calls the Dispose and Dispose methods to release the resources used by the two drawing objects. Lastly, the code calls the Flush method to send the buffered response to the requesting client.

NoteNote

In code, the HttpResponse object is referred to by the keyword Response. For example, Response.Clear() refers to the HttpResponse.Clear method. The Page class has a property that is named Response that exposes the current instance of HttpResponse.


<%@ 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 clears all content output from the buffer stream.
        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 xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>ASP.NET Example</title>
</head>
<body>
    <form id="form1" runat="server">
    </form>
</body>
</html>


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.