Programming Microsoft ASP.NET 4 - Dino Esposito [340]
Properties of the HttpResponse Class
All properties of the class are grouped and described in Table 16-10. You set a few of these properties to configure key fields on the HTTP response packet, such as content type, character set, page expiration, and status code.
Table 16-10. HttpResponse Properties
Property
Description
Buffer
Indicates whether the response text should be buffered and sent only at the end of the request. This property is deprecated and provided only for backward compatibility with classic ASP. ASP.NET applications should instead use BufferOutput.
BufferOutput
Gets or sets a Boolean value that indicates whether response buffering is enabled. The default is true.
Cache
Gets the caching policy set for the page. The caching policy is an HttpCachePolicy object that can be used to set the cache-specific HTTP headers for the current response.
CacheControl
Sets the Cache-Control HTTP header. Acceptable values are Public, Private, or No-Cache. The property is deprecated in favor of Cache.
Charset
Gets or sets a string for the HTTP character set of the output stream. If set to null, it suppresses the Content-Type header.
ContentEncoding
Gets or sets an object of type Encoding for the character encoding of the output stream.
ContentType
Gets or sets the string that represents the Multipurpose Internet Mail Extensions (MIME) type of the output stream. The default value is text/html.
Cookies
Gets a collection ( HttpCookieCollection) object that contains instances of the HttpCookie class generated on the server. All the cookies in the collection will be transmitted to the client through the set-cookie HTTP header.
Expires
Gets or sets the number of minutes before a page cached on a browser expires. Provided for compatibility with ASP, the property is deprecated in favor of Cache.
ExpiresAbsolute
Gets or sets the absolute date and time at which the page expires in the browser cache. Provided for compatibility with ASP, the property is deprecated in favor of Cache.
Filter
Gets or sets a filter Stream object through which all HTTP output is directed.
HeaderEncoding
Gets or sets an Encoding object that represents the encoding for the current header output stream.
Headers
Gets the collection of response headers. The property is supported only in integrated pipeline mode.
IsClientConnected
Indicates whether the client is still connected.
IsRequestBeingRedirected
Indicates whether the request is being redirected.
Output
Gets the writer object used to send text out.
OutputStream
Gets the Stream object used to output binary data to the response stream.
RedirectLocation
Gets or a sets a string for the value of the Location header.
Status
Sets the string returned to the client describing the status of the response. Provided for compatibility with ASP, the property is deprecated in favor of StatusDescription.
StatusCode
Gets or sets an integer value for the HTTP status code of the output returned to the client. The default value is 200.
SubStatusCode
Indicates the sub status code of the response. The property is supported only in integrated pipeline mode.
StatusDescription
Gets or sets the HTTP status string, which is a description of the overall status of the response returned to the client. The default value is OK.
SuppressContent
Gets or sets a Boolean value that indicates whether HTTP content should be sent to the client. This is set to false by default; if it is set to true, only headers are sent.
TrySkipIisCustomErrors
Boolean property, indicates whether or not custom errors set at the IIS level should by ignored by ASP.NET. The default value when running in Integrated mode is false. The property is effective only for applications hosted in IIS 7 or later.
Let’s find out more about cache and expiration properties.
Setting the Response Cache Policy
The response object has three properties