HttpResponse Class

Represents the outgoing side of an individual HTTP request.

Namespace
Microsoft.AspNetCore.Http
Assemblies
  • Microsoft.AspNetCore.Http.Abstractions

Syntax

public abstract class HttpResponse
class Microsoft.AspNetCore.Http.HttpResponse

Properties

Microsoft.AspNetCore.Http.HttpResponse.Body

Gets the response body System.IO.Stream.

Return type:System.IO.Stream
public abstract Stream Body { get; set; }
Microsoft.AspNetCore.Http.HttpResponse.ContentLength

Gets or sets the value for the <code>Content-Length</code> response header.

Return type:System.Nullable<System.Int64>
public abstract long ? ContentLength { get; set; }
Microsoft.AspNetCore.Http.HttpResponse.ContentType

Gets or sets the value for the <code>Content-Type</code> response header.

Return type:System.String
public abstract string ContentType { get; set; }
Microsoft.AspNetCore.Http.HttpResponse.Cookies

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

Return type:Microsoft.AspNetCore.Http.IResponseCookies
public abstract IResponseCookies Cookies { get; }
Microsoft.AspNetCore.Http.HttpResponse.HasStarted

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

Return type:System.Boolean
public abstract bool HasStarted { get; }
Microsoft.AspNetCore.Http.HttpResponse.Headers

Gets the response headers.

Return type:Microsoft.AspNetCore.Http.IHeaderDictionary
public abstract IHeaderDictionary Headers { get; }
Microsoft.AspNetCore.Http.HttpResponse.HttpContext

Gets the Microsoft.AspNetCore.Http.HttpResponse.HttpContext for this request.

Return type:Microsoft.AspNetCore.Http.HttpContext
public abstract HttpContext HttpContext { get; }
Microsoft.AspNetCore.Http.HttpResponse.StatusCode

Gets or sets the HTTP response code.

Return type:System.Int32
public abstract int StatusCode { get; set; }

Methods

OnCompleted(System.Func<System.Object, System.Threading.Tasks.Task>, System.Object)

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

Arguments:
  • callback (System.Func<System.Object>) – The delegate to invoke.
  • state (System.Object) – A state object to capture and pass back to the delegate.
public abstract void OnCompleted(Func<object, Task> callback, object state)
OnCompleted(System.Func<System.Threading.Tasks.Task>)

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

Arguments:callback (System.Func<System.Threading.Tasks.Task>) – The delegate to invoke.
public virtual void OnCompleted(Func<Task> callback)
OnStarting(System.Func<System.Object, System.Threading.Tasks.Task>, System.Object)

Adds a delegate to be invoked just before response headers will be sent to the client.

Arguments:
  • callback (System.Func<System.Object>) – The delegate to execute.
  • state (System.Object) – A state object to capture and pass back to the delegate.
public abstract void OnStarting(Func<object, Task> callback, object state)
OnStarting(System.Func<System.Threading.Tasks.Task>)

Adds a delegate to be invoked just before response headers will be sent to the client.

Arguments:callback (System.Func<System.Threading.Tasks.Task>) – The delegate to execute.
public virtual void OnStarting(Func<Task> callback)
Redirect(System.String)

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

Arguments:location (System.String) – The URL to redirect the client to.
public virtual void Redirect(string location)
Redirect(System.String, System.Boolean)

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

Arguments:
  • location (System.String) – The URL to redirect the client to.
  • permanent (System.Boolean) – <code>True</code> if the redirect is permanent (301), otherwise <code>false</code> (302).
public abstract void Redirect(string location, bool permanent)
RegisterForDispose(System.IDisposable)

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

Arguments:disposable (System.IDisposable) – The object to be disposed.
public virtual void RegisterForDispose(IDisposable disposable)