HttpResponse Class

Definition

Represents the outgoing side of an individual HTTP request.

public ref class HttpResponse abstract
public abstract class HttpResponse
type HttpResponse = class
Public MustInherit Class HttpResponse
Inheritance
HttpResponse

Constructors

HttpResponse()

Properties

Body

Gets or sets the response body Stream.

BodyWriter

Gets the response body PipeWriter

ContentLength

Gets or sets the value for the Content-Length response header.

ContentType

Gets or sets the value for the Content-Type response header.

Cookies

Gets an object that can be used to manage cookies for this response.

HasStarted

Gets a value indicating whether response headers have been sent to the client.

Headers

Gets the response headers.

HttpContext

Gets the HttpContext for this response.

StatusCode

Gets or sets the HTTP response code.

Methods

CompleteAsync()

Flush any remaining response headers, data, or trailers. This may throw if the response is in an invalid state such as a Content-Length mismatch.

OnCompleted(Func<Object,Task>, Object)

Adds a delegate to be invoked after the response has finished being sent to the client.

OnCompleted(Func<Task>)

Adds a delegate to be invoked after the response has finished being sent to the client.

OnStarting(Func<Object,Task>, Object)

Adds a delegate to be invoked just before response headers will be sent to the client. Callbacks registered here run in reverse order.

OnStarting(Func<Task>)

Adds a delegate to be invoked just before response headers will be sent to the client. Callbacks registered here run in reverse order.

Redirect(String)

Returns a temporary redirect response (HTTP 302) to the client.

Redirect(String, Boolean)

Returns a redirect response (HTTP 301 or HTTP 302) to the client.

RegisterForDispose(IDisposable)

Registers an object for disposal by the host once the request has finished processing.

RegisterForDisposeAsync(IAsyncDisposable)

Registers an object for asynchronous disposal by the host once the request has finished processing.

StartAsync(CancellationToken)

Starts the response by calling OnStarting() and making headers unmodifiable.

Extension Methods

GetTypedHeaders(HttpResponse)

Gets strongly typed HTTP response headers.

WriteAsJsonAsync(HttpResponse, Object, JsonTypeInfo, String, CancellationToken)

Write the specified value as JSON to the response body. The response content-type will be set to the specified content-type.

WriteAsJsonAsync(HttpResponse, Object, Type, JsonSerializerOptions, String, CancellationToken)

Write the specified value as JSON to the response body. The response content-type will be set to the specified content-type.

WriteAsJsonAsync(HttpResponse, Object, Type, JsonSerializerOptions, CancellationToken)

Write the specified value as JSON to the response body. The response content-type will be set to application/json; charset=utf-8.

WriteAsJsonAsync(HttpResponse, Object, Type, JsonSerializerContext, String, CancellationToken)

Write the specified value as JSON to the response body. The response content-type will be set to the specified content-type.

WriteAsJsonAsync(HttpResponse, Object, Type, CancellationToken)

Write the specified value as JSON to the response body. The response content-type will be set to application/json; charset=utf-8.

WriteAsJsonAsync<TValue>(HttpResponse, TValue, JsonSerializerOptions, String, CancellationToken)

Write the specified value as JSON to the response body. The response content-type will be set to the specified content-type.

WriteAsJsonAsync<TValue>(HttpResponse, TValue, JsonSerializerOptions, CancellationToken)

Write the specified value as JSON to the response body. The response content-type will be set to application/json; charset=utf-8.

WriteAsJsonAsync<TValue>(HttpResponse, TValue, JsonTypeInfo<TValue>, String, CancellationToken)

Write the specified value as JSON to the response body. The response content-type will be set to the specified content-type.

WriteAsJsonAsync<TValue>(HttpResponse, TValue, CancellationToken)

Write the specified value as JSON to the response body. The response content-type will be set to application/json; charset=utf-8.

WriteAsync(HttpResponse, String, Encoding, CancellationToken)

Writes the given text to the response body using the given encoding.

WriteAsync(HttpResponse, String, CancellationToken)

Writes the given text to the response body. UTF-8 encoding will be used.

Clear(HttpResponse)

Clears the HTTP response.

This invocation resets the response headers, response status code, and response body.

Redirect(HttpResponse, String, Boolean, Boolean)

Returns a redirect response (HTTP 301, HTTP 302, HTTP 307 or HTTP 308) to the client.

AppendTrailer(HttpResponse, String, StringValues)

Adds the given trailer header to the trailers collection to be sent at the end of the response body. Check SupportsTrailers(HttpResponse) or an InvalidOperationException may be thrown.

DeclareTrailer(HttpResponse, String)

Adds the given trailer name to the 'Trailer' response header. This must happen before the response headers are sent.

SupportsTrailers(HttpResponse)

Indicates if the server supports sending trailer headers for this response.

SendFileAsync(HttpResponse, IFileInfo, Int64, Nullable<Int64>, CancellationToken)

Sends the given file using the SendFile extension.

SendFileAsync(HttpResponse, IFileInfo, CancellationToken)

Sends the given file using the SendFile extension.

SendFileAsync(HttpResponse, String, Int64, Nullable<Int64>, CancellationToken)

Sends the given file using the SendFile extension.

SendFileAsync(HttpResponse, String, CancellationToken)

Sends the given file using the SendFile extension.

Applies to