Unosquare
    Show / Hide Table of Contents

    Class HttpException

    When thrown, breaks the request handling control flow and sends an error response to the client.

    Inheritance
    Object
    HttpException
    HttpNotAcceptableException
    HttpRangeNotSatisfiableException
    HttpRedirectException
    Implements
    IHttpException
    Namespace: EmbedIO
    Syntax
    public class HttpException : Exception, IHttpException

    Constructors

    HttpException(HttpStatusCode)

    Initializes a new instance of the HttpException class, with no message to include in the response.

    Declaration
    public HttpException(HttpStatusCode statusCode)
    Parameters
    Type Name Description
    HttpStatusCode statusCode

    The status code to set on the response.

    HttpException(HttpStatusCode, String)

    Initializes a new instance of the HttpException class, with a message to include in the response.

    Declaration
    public HttpException(HttpStatusCode statusCode, string message)
    Parameters
    Type Name Description
    HttpStatusCode statusCode

    The status code to set on the response.

    String message

    A message to include in the response as plain text.

    HttpException(HttpStatusCode, String, Object)

    Initializes a new instance of the HttpException class, with a message and a data object to include in the response.

    Declaration
    public HttpException(HttpStatusCode statusCode, string message, object data)
    Parameters
    Type Name Description
    HttpStatusCode statusCode

    The status code to set on the response.

    String message

    A message to include in the response as plain text.

    Object data

    The data object to include in the response.

    HttpException(Int32)

    Initializes a new instance of the HttpException class, with no message to include in the response.

    Declaration
    public HttpException(int statusCode)
    Parameters
    Type Name Description
    Int32 statusCode

    The status code to set on the response.

    HttpException(Int32, String)

    Initializes a new instance of the HttpException class, with a message to include in the response.

    Declaration
    public HttpException(int statusCode, string message)
    Parameters
    Type Name Description
    Int32 statusCode

    The status code to set on the response.

    String message

    A message to include in the response as plain text.

    HttpException(Int32, String, Object)

    Initializes a new instance of the HttpException class, with a message and a data object to include in the response.

    Declaration
    public HttpException(int statusCode, string message, object data)
    Parameters
    Type Name Description
    Int32 statusCode

    The status code to set on the response.

    String message

    A message to include in the response as plain text.

    Object data

    The data object to include in the response.

    Properties

    DataObject

    Gets an object that can be serialized and included in the response triggered by a HTTP exception.

    Whether the object is actually sent to the client will depend upon the handler used to send the response.

    Declaration
    public object DataObject { get; }
    Property Value
    Type Description
    Object

    StatusCode

    Gets the response status code for a HTTP exception.

    Declaration
    public int StatusCode { get; }
    Property Value
    Type Description
    Int32

    Methods

    BadRequest(String, Object)

    Returns a new instance of HttpException that, when thrown, will break the request handling control flow and send a 400 Bad Request response to the client.

    Declaration
    public static HttpException BadRequest(string message = null, object data = null)
    Parameters
    Type Name Description
    String message

    A message to include in the response.

    Object data

    The data object to include in the response.

    Returns
    Type Description
    HttpException

    A newly-created HttpException.

    Forbidden(String, Object)

    Returns a new instance of HttpException that, when thrown, will break the request handling control flow and send a 403 Forbidden response to the client.

    Declaration
    public static HttpException Forbidden(string message = null, object data = null)
    Parameters
    Type Name Description
    String message

    A message to include in the response.

    Object data

    The data object to include in the response.

    Returns
    Type Description
    HttpException

    A newly-created HttpException.

    InternalServerError(String, Object)

    Returns a new instance of HttpException that, when thrown, will break the request handling control flow and send a 500 Internal Server Error response to the client.

    Declaration
    public static HttpException InternalServerError(string message = null, object data = null)
    Parameters
    Type Name Description
    String message

    A message to include in the response.

    Object data

    The data object to include in the response.

    Returns
    Type Description
    HttpException

    A newly-created HttpException.

    MethodNotAllowed(String, Object)

    Returns a new instance of HttpException that, when thrown, will break the request handling control flow and send a 405 Method Not Allowed response to the client.

    Declaration
    public static HttpException MethodNotAllowed(string message = null, object data = null)
    Parameters
    Type Name Description
    String message

    A message to include in the response.

    Object data

    The data object to include in the response.

    Returns
    Type Description
    HttpException

    A newly-created HttpException.

    NotAcceptable()

    Returns a new instance of HttpNotAcceptableException that, when thrown, will break the request handling control flow and send a 406 Not Acceptable response to the client.

    Declaration
    public static HttpNotAcceptableException NotAcceptable()
    Returns
    Type Description
    HttpNotAcceptableException

    A newly-created HttpNotAcceptableException.

    See Also
    HttpNotAcceptableException()

    NotAcceptable(String)

    Returns a new instance of HttpNotAcceptableException that, when thrown, will break the request handling control flow and send a 406 Not Acceptable response to the client.

    Declaration
    public static HttpNotAcceptableException NotAcceptable(string vary)
    Parameters
    Type Name Description
    String vary

    A value, or a comma-separated list of values, to set the response's Vary header to.

    Returns
    Type Description
    HttpNotAcceptableException

    A newly-created HttpNotAcceptableException.

    See Also
    HttpNotAcceptableException(String)

    NotFound(String, Object)

    Returns a new instance of HttpException that, when thrown, will break the request handling control flow and send a 404 Not Found response to the client.

    Declaration
    public static HttpException NotFound(string message = null, object data = null)
    Parameters
    Type Name Description
    String message

    A message to include in the response.

    Object data

    The data object to include in the response.

    Returns
    Type Description
    HttpException

    A newly-created HttpException.

    PrepareResponse(IHttpContext)

    Sets necessary headers, as required by the nature of the HTTP exception (e.g. Location for HttpRedirectException).

    Declaration
    public virtual void PrepareResponse(IHttpContext context)
    Parameters
    Type Name Description
    IHttpContext context

    The HTTP context of the response.

    Remarks

    This method does nothing; there is no need to call base.PrepareResponse in overrides of this method.

    RangeNotSatisfiable()

    Returns a new instance of HttpRangeNotSatisfiableException that, when thrown, will break the request handling control flow and send a 416 Range Not Satisfiable response to the client.

    Declaration
    public static HttpRangeNotSatisfiableException RangeNotSatisfiable()
    Returns
    Type Description
    HttpRangeNotSatisfiableException

    A newly-created HttpRangeNotSatisfiableException.

    See Also
    HttpRangeNotSatisfiableException()

    RangeNotSatisfiable(Nullable<Int64>)

    Returns a new instance of HttpRangeNotSatisfiableException that, when thrown, will break the request handling control flow and send a 416 Range Not Satisfiable response to the client.

    Declaration
    public static HttpRangeNotSatisfiableException RangeNotSatisfiable(long? contentLength)
    Parameters
    Type Name Description
    Nullable<Int64> contentLength

    The total length of the requested resource, expressed in bytes, or null to omit the Content-Range header in the response.

    Returns
    Type Description
    HttpRangeNotSatisfiableException

    A newly-created HttpRangeNotSatisfiableException.

    See Also
    HttpRangeNotSatisfiableException()

    Redirect(String)

    Returns a new instance of HttpRedirectException that, when thrown, will break the request handling control flow and redirect the client to the specified location, using response status code 302.

    Declaration
    public static HttpRedirectException Redirect(string location)
    Parameters
    Type Name Description
    String location

    The redirection target.

    Returns
    Type Description
    HttpRedirectException

    A newly-created HttpRedirectException.

    Redirect(String, HttpStatusCode)

    Returns a new instance of HttpRedirectException that, when thrown, will break the request handling control flow and redirect the client to the specified location, using the specified response status code.

    Declaration
    public static HttpRedirectException Redirect(string location, HttpStatusCode statusCode)
    Parameters
    Type Name Description
    String location

    The redirection target.

    HttpStatusCode statusCode

    One of the redirection status codes, to be set on the response.

    Returns
    Type Description
    HttpRedirectException

    A newly-created HttpRedirectException.

    Redirect(String, Int32)

    Returns a new instance of HttpRedirectException that, when thrown, will break the request handling control flow and redirect the client to the specified location, using the specified response status code.

    Declaration
    public static HttpRedirectException Redirect(string location, int statusCode)
    Parameters
    Type Name Description
    String location

    The redirection target.

    Int32 statusCode

    The status code to set on the response, in the range from 300 to 399.

    Returns
    Type Description
    HttpRedirectException

    A newly-created HttpRedirectException.

    Unauthorized(String, Object)

    Returns a new instance of HttpException that, when thrown, will break the request handling control flow and send a 401 Unauthorized response to the client.

    Declaration
    public static HttpException Unauthorized(string message = null, object data = null)
    Parameters
    Type Name Description
    String message

    A message to include in the response.

    Object data

    The data object to include in the response.

    Returns
    Type Description
    HttpException

    A newly-created HttpException.

    Explicit Interface Implementations

    IHttpException.Message

    Gets a message that can be included in the response triggered by a HTTP exception.

    Whether the message is actually sent to the client will depend upon the handler used to send the response.

    Declaration
    string IHttpException.Message { get; }
    Returns
    Type Description
    String
    Remarks

    Do not rely on to implement this property if you want to support null messages, because a default message will be supplied by the CLR at throw time when is null.

    Implements

    IHttpException

    Comments

    Back to top Copyright © 2017-2019 Unosquare