ApiController Class

Namespace
System.Web.Http
Assemblies
  • Microsoft.AspNetCore.Mvc.WebApiCompatShim

Syntax

public abstract class ApiController : IDisposable
class System.Web.Http.ApiController

Properties

System.Web.Http.ApiController.ActionContext

Gets the Microsoft.AspNetCore.Mvc.ActionContext.

Return type:Microsoft.AspNetCore.Mvc.ActionContext
public ActionContext ActionContext { get; }
System.Web.Http.ApiController.Context

Gets the http context.

Return type:Microsoft.AspNetCore.Http.HttpContext
public HttpContext Context { get; }
System.Web.Http.ApiController.ControllerContext

Gets or sets the System.Web.Http.ApiController.ControllerContext.

Return type:Microsoft.AspNetCore.Mvc.ControllerContext
public ControllerContext ControllerContext { get; set; }
System.Web.Http.ApiController.MetadataProvider

Gets the Microsoft.AspNetCore.Mvc.ModelBinding.IModelMetadataProvider.

Return type:Microsoft.AspNetCore.Mvc.ModelBinding.IModelMetadataProvider
public IModelMetadataProvider MetadataProvider { get; set; }
System.Web.Http.ApiController.ModelState

Gets model state after the model binding process. This ModelState will be empty before model binding happens.

Return type:Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary
public ModelStateDictionary ModelState { get; }
System.Web.Http.ApiController.ObjectValidator

Gets or sets the Microsoft.AspNetCore.Mvc.ModelBinding.Validation.IObjectModelValidator.

Return type:Microsoft.AspNetCore.Mvc.ModelBinding.Validation.IObjectModelValidator
public IObjectModelValidator ObjectValidator { get; set; }
System.Web.Http.ApiController.Request

Gets or sets the HTTP request message.

Return type:System.Net.Http.HttpRequestMessage
public HttpRequestMessage Request { get; set; }
System.Web.Http.ApiController.Url

Gets a factory used to generate URLs to other APIs.

Return type:Microsoft.AspNetCore.Mvc.IUrlHelper
public IUrlHelper Url { get; set; }
System.Web.Http.ApiController.User

Gets or sets the current principal associated with this request.

Return type:System.Security.Principal.IPrincipal
public IPrincipal User { get; }

Methods

BadRequest()

Creates a Microsoft.AspNetCore.Mvc.BadRequestResult (400 Bad Request).

Return type:Microsoft.AspNetCore.Mvc.BadRequestResult
Returns:A Microsoft.AspNetCore.Mvc.BadRequestResult.
public virtual BadRequestResult BadRequest()
BadRequest(Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary)

Creates an System.Web.Http.InvalidModelStateResult (400 Bad Request) with the specified model state.

Arguments:modelState (Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary) – The model state to include in the error.
Return type:System.Web.Http.InvalidModelStateResult
Returns:An System.Web.Http.InvalidModelStateResult with the specified model state.
public virtual InvalidModelStateResult BadRequest(ModelStateDictionary modelState)
BadRequest(System.String)

Creates a System.Web.Http.BadRequestErrorMessageResult (400 Bad Request) with the specified error message.

Arguments:message (System.String) – The user-visible error message.
Return type:System.Web.Http.BadRequestErrorMessageResult
Returns:A System.Web.Http.BadRequestErrorMessageResult with the specified error message.
public virtual BadRequestErrorMessageResult BadRequest(string message)
Conflict()

Creates a System.Web.Http.ConflictResult (409 Conflict).

Return type:System.Web.Http.ConflictResult
Returns:A System.Web.Http.ConflictResult.
public virtual ConflictResult Conflict()
Content<T>(System.Net.HttpStatusCode, T)

Creates a System.Web.Http.NegotiatedContentResult`1 with the specified values.

Arguments:
  • statusCode (System.Net.HttpStatusCode) – The HTTP status code for the response message.
  • value (T) – The content value to negotiate and format in the entity body.
Return type:

System.Web.Http.NegotiatedContentResult<T>

Returns:

A System.Web.Http.NegotiatedContentResult`1 with the specified values.

public virtual NegotiatedContentResult<T> Content<T>(HttpStatusCode statusCode, T value)
Created(System.String, System.Object)

Creates a Microsoft.AspNetCore.Mvc.CreatedResult (201 Created) with the specified values.

Arguments:
  • location (System.String) – The location at which the content has been created. Must be a relative or absolute URL.
  • content (System.Object) – The content value to format in the entity body.
Return type:

Microsoft.AspNetCore.Mvc.CreatedResult

Returns:

A Microsoft.AspNetCore.Mvc.CreatedResult with the specified values.

public virtual CreatedResult Created(string location, object content)
Created(System.Uri, System.Object)

Creates a Microsoft.AspNetCore.Mvc.CreatedResult (201 Created) with the specified values.

Arguments:
  • uri (System.Uri) – The location at which the content has been created.
  • content (System.Object) – The content value to format in the entity body.
Return type:

Microsoft.AspNetCore.Mvc.CreatedResult

Returns:

A Microsoft.AspNetCore.Mvc.CreatedResult with the specified values.

public virtual CreatedResult Created(Uri uri, object content)
CreatedAtRoute(System.String, System.Object, System.Object)

Creates a Microsoft.AspNetCore.Mvc.CreatedAtRouteResult (201 Created) with the specified values.

Arguments:
  • routeName (System.String) – The name of the route to use for generating the URL.
  • routeValues (System.Object) – The route data to use for generating the URL.
  • content (System.Object) – The content value to format in the entity body.
Return type:

Microsoft.AspNetCore.Mvc.CreatedAtRouteResult

Returns:

A Microsoft.AspNetCore.Mvc.CreatedAtRouteResult with the specified values.

public virtual CreatedAtRouteResult CreatedAtRoute(string routeName, object routeValues, object content)
Dispose()
public void Dispose()
Dispose(System.Boolean)
protected virtual void Dispose(bool disposing)
InternalServerError()

Creates an System.Web.Http.InternalServerErrorResult (500 Internal Server Error).

Return type:System.Web.Http.InternalServerErrorResult
Returns:A System.Web.Http.InternalServerErrorResult.
public virtual InternalServerErrorResult InternalServerError()
InternalServerError(System.Exception)

Creates an System.Web.Http.ExceptionResult (500 Internal Server Error) with the specified exception.

Arguments:exception (System.Exception) – The exception to include in the error.
Return type:System.Web.Http.ExceptionResult
Returns:An System.Web.Http.ExceptionResult with the specified exception.
public virtual ExceptionResult InternalServerError(Exception exception)
Json<T>(T)

Creates an Microsoft.AspNetCore.Mvc.JsonResult (200 OK) with the specified value.

Arguments:content (T) – The content value to serialize in the entity body.
Return type:Microsoft.AspNetCore.Mvc.JsonResult
Returns:A Microsoft.AspNetCore.Mvc.JsonResult with the specified value.
public virtual JsonResult Json<T>(T content)
Json<T>(T, Newtonsoft.Json.JsonSerializerSettings)

Creates an Microsoft.AspNetCore.Mvc.JsonResult (200 OK) with the specified values.

Arguments:
  • content (T) – The content value to serialize in the entity body.
  • serializerSettings (Newtonsoft.Json.JsonSerializerSettings) – The serializer settings.
Return type:

Microsoft.AspNetCore.Mvc.JsonResult

Returns:

A Microsoft.AspNetCore.Mvc.JsonResult with the specified values.

public virtual JsonResult Json<T>(T content, JsonSerializerSettings serializerSettings)
Json<T>(T, Newtonsoft.Json.JsonSerializerSettings, System.Text.Encoding)

Creates an Microsoft.AspNetCore.Mvc.JsonResult (200 OK) with the specified values.

Arguments:
  • content (T) – The content value to serialize in the entity body.
  • serializerSettings (Newtonsoft.Json.JsonSerializerSettings) – The serializer settings.
  • encoding (System.Text.Encoding) – The content encoding.
Return type:

Microsoft.AspNetCore.Mvc.JsonResult

Returns:

A Microsoft.AspNetCore.Mvc.JsonResult with the specified values.

public virtual JsonResult Json<T>(T content, JsonSerializerSettings serializerSettings, Encoding encoding)
NotFound()

Creates an Microsoft.AspNetCore.Mvc.NotFoundResult (404 Not Found).

Return type:Microsoft.AspNetCore.Mvc.NotFoundResult
Returns:A Microsoft.AspNetCore.Mvc.NotFoundResult.
public virtual NotFoundResult NotFound()
Ok()

Creates an Microsoft.AspNetCore.Mvc.OkResult (200 OK).

Return type:Microsoft.AspNetCore.Mvc.OkResult
Returns:An Microsoft.AspNetCore.Mvc.OkResult.
public virtual OkResult Ok()
Ok<T>(T)

Creates an Microsoft.AspNetCore.Mvc.OkObjectResult (200 OK) with the specified values.

Arguments:content (T) – The content value to negotiate and format in the entity body.
Return type:Microsoft.AspNetCore.Mvc.OkObjectResult
Returns:An Microsoft.AspNetCore.Mvc.OkObjectResult with the specified values.
public virtual OkObjectResult Ok<T>(T content)
Redirect(System.String)

Creates a Microsoft.AspNetCore.Mvc.RedirectResult (302 Found) with the specified value.

Arguments:location (System.String) – The location to which to redirect.
Return type:Microsoft.AspNetCore.Mvc.RedirectResult
Returns:A Microsoft.AspNetCore.Mvc.RedirectResult with the specified value.
public virtual RedirectResult Redirect(string location)
Redirect(System.Uri)

Creates a Microsoft.AspNetCore.Mvc.RedirectResult (302 Found) with the specified value.

Arguments:location (System.Uri) – The location to which to redirect.
Return type:Microsoft.AspNetCore.Mvc.RedirectResult
Returns:A Microsoft.AspNetCore.Mvc.RedirectResult with the specified value.
public virtual RedirectResult Redirect(Uri location)
RedirectToRoute(System.String, System.Object)

Creates a Microsoft.AspNetCore.Mvc.RedirectToRouteResult (302 Found) with the specified values.

Arguments:
  • routeName (System.String) – The name of the route to use for generating the URL.
  • routeValues (System.Object) – The route data to use for generating the URL.
Return type:

Microsoft.AspNetCore.Mvc.RedirectToRouteResult

Returns:

A Microsoft.AspNetCore.Mvc.RedirectToRouteResult with the specified values.

public virtual RedirectToRouteResult RedirectToRoute(string routeName, object routeValues)
ResponseMessage(System.Net.Http.HttpResponseMessage)

Creates a System.Web.Http.ResponseMessageResult with the specified response.

Arguments:response (System.Net.Http.HttpResponseMessage) – The HTTP response message.
Return type:System.Web.Http.ResponseMessageResult
Returns:A System.Web.Http.ResponseMessageResult for the specified response.
public virtual ResponseMessageResult ResponseMessage(HttpResponseMessage response)
StatusCode(System.Net.HttpStatusCode)

Creates a Microsoft.AspNetCore.Mvc.StatusCodeResult with the specified status code.

Arguments:status (System.Net.HttpStatusCode) – The HTTP status code for the response message
Return type:Microsoft.AspNetCore.Mvc.StatusCodeResult
Returns:A Microsoft.AspNetCore.Mvc.StatusCodeResult with the specified status code.
public virtual StatusCodeResult StatusCode(HttpStatusCode status)
Validate<TEntity>(TEntity)

Validates the given entity and adds the validation errors to the System.Web.Http.ApiController.ModelState under an empty prefix.

Arguments:entity (TEntity) – The entity being validated.
public void Validate<TEntity>(TEntity entity)
Validate<TEntity>(TEntity, System.String)

Validates the given entity and adds the validation errors to the System.Web.Http.ApiController.ModelState.

Arguments:
public void Validate<TEntity>(TEntity entity, string keyPrefix)