// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.IO; using System.Linq.Expressions; using System.Security.Claims; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Authentication; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Core; using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.AspNetCore.Mvc.ModelBinding.Internal; using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; using Microsoft.Net.Http.Headers; namespace Microsoft.AspNetCore.Mvc { /// /// A base class for an MVC controller without view support. /// [Controller] public abstract class ControllerBase { private ControllerContext _controllerContext; private IModelMetadataProvider _metadataProvider; private IModelBinderFactory _modelBinderFactory; private IObjectModelValidator _objectValidator; private IUrlHelper _url; /// /// Gets the for the executing action. /// public HttpContext HttpContext => ControllerContext.HttpContext; /// /// Gets the for the executing action. /// public HttpRequest Request => HttpContext?.Request; /// /// Gets the for the executing action. /// public HttpResponse Response => HttpContext?.Response; /// /// Gets the for the executing action. /// public RouteData RouteData => ControllerContext.RouteData; /// /// Gets the that contains the state of the model and of model-binding validation. /// public ModelStateDictionary ModelState => ControllerContext.ModelState; /// /// Gets or sets the . /// /// /// activates this property while activating controllers. /// If user code directly instantiates a controller, the getter returns an empty /// . /// [ControllerContext] public ControllerContext ControllerContext { get { if (_controllerContext == null) { _controllerContext = new ControllerContext(); } return _controllerContext; } set { if (value == null) { throw new ArgumentNullException(nameof(value)); } _controllerContext = value; } } /// /// Gets or sets the . /// public IModelMetadataProvider MetadataProvider { get { if (_metadataProvider == null) { _metadataProvider = HttpContext?.RequestServices?.GetRequiredService(); } return _metadataProvider; } set { if (value == null) { throw new ArgumentNullException(nameof(value)); } _metadataProvider = value; } } /// /// Gets or sets the . /// public IModelBinderFactory ModelBinderFactory { get { if (_modelBinderFactory == null) { _modelBinderFactory = HttpContext?.RequestServices?.GetRequiredService(); } return _modelBinderFactory; } set { if (value == null) { throw new ArgumentNullException(nameof(value)); } _modelBinderFactory = value; } } /// /// Gets or sets the . /// public IUrlHelper Url { get { if (_url == null) { var factory = HttpContext?.RequestServices?.GetRequiredService(); _url = factory?.GetUrlHelper(ControllerContext); } return _url; } set { if (value == null) { throw new ArgumentNullException(nameof(value)); } _url = value; } } /// /// Gets or sets the . /// public IObjectModelValidator ObjectValidator { get { if (_objectValidator == null) { _objectValidator = HttpContext?.RequestServices?.GetRequiredService(); } return _objectValidator; } set { if (value == null) { throw new ArgumentNullException(nameof(value)); } _objectValidator = value; } } /// /// Gets the for user associated with the executing action. /// public ClaimsPrincipal User => HttpContext?.User; /// /// Creates a object by specifying a . /// /// The status code to set on the response. /// The created object for the response. [NonAction] public virtual StatusCodeResult StatusCode(int statusCode) => new StatusCodeResult(statusCode); /// /// Creates a object by specifying a and /// /// The status code to set on the response. /// The value to set on the . /// The created object for the response. [NonAction] public virtual ObjectResult StatusCode(int statusCode, object value) { var result = new ObjectResult(value); result.StatusCode = statusCode; return result; } /// /// Creates a object with by specifying a /// string. /// /// The content to write to the response. /// The created object for the response. [NonAction] public virtual ContentResult Content(string content) => Content(content, (MediaTypeHeaderValue)null); /// /// Creates a object with by specifying a /// string and a content type. /// /// The content to write to the response. /// The content type (MIME type). /// The created object for the response. [NonAction] public virtual ContentResult Content(string content, string contentType) => Content(content, MediaTypeHeaderValue.Parse(contentType)); /// /// Creates a object with by specifying a /// string, a , and . /// /// The content to write to the response. /// The content type (MIME type). /// The content encoding. /// The created object for the response. /// /// If encoding is provided by both the 'charset' and the parameters, then /// the parameter is chosen as the final encoding. /// [NonAction] public virtual ContentResult Content(string content, string contentType, Encoding contentEncoding) { var mediaTypeHeaderValue = MediaTypeHeaderValue.Parse(contentType); mediaTypeHeaderValue.Encoding = contentEncoding ?? mediaTypeHeaderValue.Encoding; return Content(content, mediaTypeHeaderValue); } /// /// Creates a object with by specifying a /// string and a . /// /// The content to write to the response. /// The content type (MIME type). /// The created object for the response. [NonAction] public virtual ContentResult Content(string content, MediaTypeHeaderValue contentType) { var result = new ContentResult { Content = content, ContentType = contentType?.ToString() }; return result; } /// /// Creates a object that produces an empty /// response. /// /// The created object for the response. [NonAction] public virtual NoContentResult NoContent() => new NoContentResult(); /// /// Creates a object that produces an empty response. /// /// The created for the response. [NonAction] public virtual OkResult Ok() => new OkResult(); /// /// Creates an object that produces an response. /// /// The content value to format in the entity body. /// The created for the response. [NonAction] public virtual OkObjectResult Ok(object value) => new OkObjectResult(value); /// /// Creates a object that redirects () /// to the specified . /// /// The URL to redirect to. /// The created for the response. [NonAction] public virtual RedirectResult Redirect(string url) { if (string.IsNullOrEmpty(url)) { throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(url)); } return new RedirectResult(url); } /// /// Creates a object with set to true /// () using the specified . /// /// The URL to redirect to. /// The created for the response. [NonAction] public virtual RedirectResult RedirectPermanent(string url) { if (string.IsNullOrEmpty(url)) { throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(url)); } return new RedirectResult(url, permanent: true); } /// /// Creates a object with set to false /// and set to true () /// using the specified . /// /// The URL to redirect to. /// The created for the response. [NonAction] public virtual RedirectResult RedirectPreserveMethod(string url) { if (string.IsNullOrEmpty(url)) { throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(url)); } return new RedirectResult(url: url, permanent: false, preserveMethod: true); } /// /// Creates a object with set to true /// and set to true () /// using the specified . /// /// The URL to redirect to. /// The created for the response. [NonAction] public virtual RedirectResult RedirectPermanentPreserveMethod(string url) { if (string.IsNullOrEmpty(url)) { throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(url)); } return new RedirectResult(url: url, permanent: true, preserveMethod: true); } /// /// Creates a object that redirects /// () to the specified local . /// /// The local URL to redirect to. /// The created for the response. [NonAction] public virtual LocalRedirectResult LocalRedirect(string localUrl) { if (string.IsNullOrEmpty(localUrl)) { throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(localUrl)); } return new LocalRedirectResult(localUrl); } /// /// Creates a object with set to /// true () using the specified . /// /// The local URL to redirect to. /// The created for the response. [NonAction] public virtual LocalRedirectResult LocalRedirectPermanent(string localUrl) { if (string.IsNullOrEmpty(localUrl)) { throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(localUrl)); } return new LocalRedirectResult(localUrl, permanent: true); } /// /// Creates a object with set to /// false and set to true /// () using the specified . /// /// The local URL to redirect to. /// The created for the response. [NonAction] public virtual LocalRedirectResult LocalRedirectPreserveMethod(string localUrl) { if (string.IsNullOrEmpty(localUrl)) { throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(localUrl)); } return new LocalRedirectResult(localUrl: localUrl, permanent: false, preserveMethod: true); } /// /// Creates a object with set to /// true and set to true /// () using the specified . /// /// The local URL to redirect to. /// The created for the response. [NonAction] public virtual LocalRedirectResult LocalRedirectPermanentPreserveMethod(string localUrl) { if (string.IsNullOrEmpty(localUrl)) { throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(localUrl)); } return new LocalRedirectResult(localUrl: localUrl, permanent: true, preserveMethod: true); } /// /// Redirects () to an action with the same name as current one. /// The 'controller' and 'action' names are retrieved from the ambient values of the current request. /// /// The created for the response. /// /// A POST request to an action named "Product" updates a product and redirects to an action, also named /// "Product", showing details of the updated product. /// /// [HttpGet] /// public IActionResult Product(int id) /// { /// var product = RetrieveProduct(id); /// return View(product); /// } /// /// [HttpPost] /// public IActionResult Product(int id, Product product) /// { /// UpdateProduct(product); /// return RedirectToAction(); /// } /// /// [NonAction] public virtual RedirectToActionResult RedirectToAction() => RedirectToAction(actionName: null); /// /// Redirects () to the specified action using the . /// /// The name of the action. /// The created for the response. [NonAction] public virtual RedirectToActionResult RedirectToAction(string actionName) => RedirectToAction(actionName, routeValues: null); /// /// Redirects () to the specified action using the /// and . /// /// The name of the action. /// The parameters for a route. /// The created for the response. [NonAction] public virtual RedirectToActionResult RedirectToAction(string actionName, object routeValues) => RedirectToAction(actionName, controllerName: null, routeValues: routeValues); /// /// Redirects () to the specified action using the /// and the . /// /// The name of the action. /// The name of the controller. /// The created for the response. [NonAction] public virtual RedirectToActionResult RedirectToAction(string actionName, string controllerName) => RedirectToAction(actionName, controllerName, routeValues: null); /// /// Redirects () to the specified action using the specified /// , , and . /// /// The name of the action. /// The name of the controller. /// The parameters for a route. /// The created for the response. [NonAction] public virtual RedirectToActionResult RedirectToAction( string actionName, string controllerName, object routeValues) => RedirectToAction(actionName, controllerName, routeValues, fragment: null); /// /// Redirects () to the specified action using the specified /// , , and . /// /// The name of the action. /// The name of the controller. /// The fragment to add to the URL. /// The created for the response. [NonAction] public virtual RedirectToActionResult RedirectToAction( string actionName, string controllerName, string fragment) => RedirectToAction(actionName, controllerName, routeValues: null, fragment: fragment); /// /// Redirects () to the specified action using the specified , /// , , and . /// /// The name of the action. /// The name of the controller. /// The parameters for a route. /// The fragment to add to the URL. /// The created for the response. [NonAction] public virtual RedirectToActionResult RedirectToAction( string actionName, string controllerName, object routeValues, string fragment) { return new RedirectToActionResult(actionName, controllerName, routeValues, fragment) { UrlHelper = Url, }; } /// /// Redirects () to the specified action with /// set to false and /// set to true, using the specified , , /// , and . /// /// The name of the action. /// The name of the controller. /// The route data to use for generating the URL. /// The fragment to add to the URL. /// The created for the response. [NonAction] public virtual RedirectToActionResult RedirectToActionPreserveMethod( string actionName = null, string controllerName = null, object routeValues = null, string fragment = null) { return new RedirectToActionResult( actionName: actionName, controllerName: controllerName, routeValues: routeValues, permanent: false, preserveMethod: true, fragment: fragment) { UrlHelper = Url, }; } /// /// Redirects () to the specified action with /// set to true using the specified . /// /// The name of the action. /// The created for the response. [NonAction] public virtual RedirectToActionResult RedirectToActionPermanent(string actionName) => RedirectToActionPermanent(actionName, routeValues: null); /// /// Redirects () to the specified action with /// set to true using the specified /// and . /// /// The name of the action. /// The parameters for a route. /// The created for the response. [NonAction] public virtual RedirectToActionResult RedirectToActionPermanent(string actionName, object routeValues) => RedirectToActionPermanent(actionName, controllerName: null, routeValues: routeValues); /// /// Redirects () to the specified action with /// set to true using the specified /// and . /// /// The name of the action. /// The name of the controller. /// The created for the response. [NonAction] public virtual RedirectToActionResult RedirectToActionPermanent(string actionName, string controllerName) => RedirectToActionPermanent(actionName, controllerName, routeValues: null); /// /// Redirects () to the specified action with /// set to true using the specified , /// , and . /// /// The name of the action. /// The name of the controller. /// The fragment to add to the URL. /// The created for the response. [NonAction] public virtual RedirectToActionResult RedirectToActionPermanent( string actionName, string controllerName, string fragment) => RedirectToActionPermanent(actionName, controllerName, routeValues: null, fragment: fragment); /// /// Redirects () to the specified action with /// set to true using the specified , /// , and . /// /// The name of the action. /// The name of the controller. /// The parameters for a route. /// The created for the response. [NonAction] public virtual RedirectToActionResult RedirectToActionPermanent( string actionName, string controllerName, object routeValues) => RedirectToActionPermanent(actionName, controllerName, routeValues, fragment: null); /// /// Redirects () to the specified action with /// set to true using the specified , /// , , and . /// /// The name of the action. /// The name of the controller. /// The parameters for a route. /// The fragment to add to the URL. /// The created for the response. [NonAction] public virtual RedirectToActionResult RedirectToActionPermanent( string actionName, string controllerName, object routeValues, string fragment) { return new RedirectToActionResult( actionName, controllerName, routeValues, permanent: true, fragment: fragment) { UrlHelper = Url, }; } /// /// Redirects () to the specified action with /// set to true and /// set to true, using the specified , , /// , and . /// /// The name of the action. /// The name of the controller. /// The route data to use for generating the URL. /// The fragment to add to the URL. /// The created for the response. [NonAction] public virtual RedirectToActionResult RedirectToActionPermanentPreserveMethod( string actionName = null, string controllerName = null, object routeValues = null, string fragment = null) { return new RedirectToActionResult( actionName: actionName, controllerName: controllerName, routeValues: routeValues, permanent: true, preserveMethod: true, fragment: fragment) { UrlHelper = Url, }; } /// /// Redirects () to the specified route using the specified . /// /// The name of the route. /// The created for the response. [NonAction] public virtual RedirectToRouteResult RedirectToRoute(string routeName) => RedirectToRoute(routeName, routeValues: null); /// /// Redirects () to the specified route using the specified . /// /// The parameters for a route. /// The created for the response. [NonAction] public virtual RedirectToRouteResult RedirectToRoute(object routeValues) => RedirectToRoute(routeName: null, routeValues: routeValues); /// /// Redirects () to the specified route using the specified /// and . /// /// The name of the route. /// The parameters for a route. /// The created for the response. [NonAction] public virtual RedirectToRouteResult RedirectToRoute(string routeName, object routeValues) => RedirectToRoute(routeName, routeValues, fragment: null); /// /// Redirects () to the specified route using the specified /// and . /// /// The name of the route. /// The fragment to add to the URL. /// The created for the response. [NonAction] public virtual RedirectToRouteResult RedirectToRoute(string routeName, string fragment) => RedirectToRoute(routeName, routeValues: null, fragment: fragment); /// /// Redirects () to the specified route using the specified /// , , and . /// /// The name of the route. /// The parameters for a route. /// The fragment to add to the URL. /// The created for the response. [NonAction] public virtual RedirectToRouteResult RedirectToRoute( string routeName, object routeValues, string fragment) { return new RedirectToRouteResult(routeName, routeValues, fragment) { UrlHelper = Url, }; } /// /// Redirects () to the specified route with /// set to false and /// set to true, using the specified , , and . /// /// The name of the route. /// The route data to use for generating the URL. /// The fragment to add to the URL. /// The created for the response. [NonAction] public virtual RedirectToRouteResult RedirectToRoutePreserveMethod( string routeName = null, object routeValues = null, string fragment = null) { return new RedirectToRouteResult( routeName: routeName, routeValues: routeValues, permanent: false, preserveMethod: true, fragment: fragment) { UrlHelper = Url, }; } /// /// Redirects () to the specified route with /// set to true using the specified . /// /// The name of the route. /// The created for the response. [NonAction] public virtual RedirectToRouteResult RedirectToRoutePermanent(string routeName) => RedirectToRoutePermanent(routeName, routeValues: null); /// /// Redirects () to the specified route with /// set to true using the specified . /// /// The parameters for a route. /// The created for the response. [NonAction] public virtual RedirectToRouteResult RedirectToRoutePermanent(object routeValues) => RedirectToRoutePermanent(routeName: null, routeValues: routeValues); /// /// Redirects () to the specified route with /// set to true using the specified /// and . /// /// The name of the route. /// The parameters for a route. /// The created for the response. [NonAction] public virtual RedirectToRouteResult RedirectToRoutePermanent(string routeName, object routeValues) => RedirectToRoutePermanent(routeName, routeValues, fragment: null); /// /// Redirects () to the specified route with /// set to true using the specified /// and . /// /// The name of the route. /// The fragment to add to the URL. /// The created for the response. [NonAction] public virtual RedirectToRouteResult RedirectToRoutePermanent(string routeName, string fragment) => RedirectToRoutePermanent(routeName, routeValues: null, fragment: fragment); /// /// Redirects () to the specified route with /// set to true using the specified , /// , and . /// /// The name of the route. /// The parameters for a route. /// The fragment to add to the URL. /// The created for the response. [NonAction] public virtual RedirectToRouteResult RedirectToRoutePermanent( string routeName, object routeValues, string fragment) { return new RedirectToRouteResult(routeName, routeValues, permanent: true, fragment: fragment) { UrlHelper = Url, }; } /// /// Redirects () to the specified route with /// set to true and /// set to true, using the specified , , and . /// /// The name of the route. /// The route data to use for generating the URL. /// The fragment to add to the URL. /// The created for the response. [NonAction] public virtual RedirectToRouteResult RedirectToRoutePermanentPreserveMethod( string routeName = null, object routeValues = null, string fragment = null) { return new RedirectToRouteResult( routeName: routeName, routeValues: routeValues, permanent: true, preserveMethod: true, fragment: fragment) { UrlHelper = Url, }; } /// /// Redirects () to the specified . /// /// The name of the page. /// The . [NonAction] public virtual RedirectToPageResult RedirectToPage(string pageName) => RedirectToPage(pageName, routeValues: null); /// /// Redirects () to the specified /// using the specified . /// /// The name of the page. /// The parameters for a route. /// The . [NonAction] public virtual RedirectToPageResult RedirectToPage(string pageName, object routeValues) => RedirectToPage(pageName, pageHandler: null, routeValues: routeValues, fragment: null); /// /// Redirects () to the specified /// using the specified . /// /// The name of the page. /// The page handler to redirect to. /// The . [NonAction] public virtual RedirectToPageResult RedirectToPage(string pageName, string pageHandler) => RedirectToPage(pageName, pageHandler, routeValues: null); /// /// Redirects () to the specified . /// /// The name of the page. /// The page handler to redirect to. /// The parameters for a route. /// The . [NonAction] public virtual RedirectToPageResult RedirectToPage(string pageName, string pageHandler, object routeValues) => RedirectToPage(pageName, pageHandler, routeValues, fragment: null); /// /// Redirects () to the specified /// using the specified . /// /// The name of the page. /// The page handler to redirect to. /// The fragment to add to the URL. /// The . [NonAction] public virtual RedirectToPageResult RedirectToPage(string pageName, string pageHandler, string fragment) => RedirectToPage(pageName, pageHandler, routeValues: null, fragment: fragment); /// /// Redirects () to the specified /// using the specified and . /// /// The name of the page. /// The page handler to redirect to. /// The parameters for a route. /// The fragment to add to the URL. /// The . [NonAction] public virtual RedirectToPageResult RedirectToPage(string pageName, string pageHandler, object routeValues, string fragment) => new RedirectToPageResult(pageName, pageHandler, routeValues, fragment); /// /// Redirects () to the specified . /// /// The name of the page. /// The with set. [NonAction] public virtual RedirectToPageResult RedirectToPagePermanent(string pageName) => RedirectToPagePermanent(pageName, routeValues: null); /// /// Redirects () to the specified /// using the specified . /// /// The name of the page. /// The parameters for a route. /// The with set. [NonAction] public virtual RedirectToPageResult RedirectToPagePermanent(string pageName, object routeValues) => RedirectToPagePermanent(pageName, pageHandler: null, routeValues: routeValues, fragment: null); /// /// Redirects () to the specified /// using the specified . /// /// The name of the page. /// The page handler to redirect to. /// The with set. [NonAction] public virtual RedirectToPageResult RedirectToPagePermanent(string pageName, string pageHandler) => RedirectToPagePermanent(pageName, pageHandler, routeValues: null, fragment: null); /// /// Redirects () to the specified /// using the specified . /// /// The name of the page. /// The page handler to redirect to. /// The fragment to add to the URL. /// The with set. [NonAction] public virtual RedirectToPageResult RedirectToPagePermanent(string pageName, string pageHandler, string fragment) => RedirectToPagePermanent(pageName, pageHandler, routeValues: null, fragment: fragment); /// /// Redirects () to the specified /// using the specified and . /// /// The name of the page. /// The page handler to redirect to. /// The parameters for a route. /// The fragment to add to the URL. /// The with set. [NonAction] public virtual RedirectToPageResult RedirectToPagePermanent( string pageName, string pageHandler, object routeValues, string fragment) => new RedirectToPageResult(pageName, pageHandler, routeValues, permanent: true, fragment: fragment); /// /// Redirects () to the specified page with /// set to false and /// set to true, using the specified , , and . /// /// The name of the page. /// The page handler to redirect to. /// The route data to use for generating the URL. /// The fragment to add to the URL. /// The created for the response. [NonAction] public virtual RedirectToPageResult RedirectToPagePreserveMethod( string pageName, string pageHandler = null, object routeValues = null, string fragment = null) { if (pageName == null) { throw new ArgumentNullException(nameof(pageName)); } return new RedirectToPageResult( pageName: pageName, pageHandler: pageHandler, routeValues: routeValues, permanent: false, preserveMethod: true, fragment: fragment); } /// /// Redirects () to the specified route with /// set to true and /// set to true, using the specified , , and . /// /// The name of the page. /// The page handler to redirect to. /// The route data to use for generating the URL. /// The fragment to add to the URL. /// The created for the response. [NonAction] public virtual RedirectToPageResult RedirectToPagePermanentPreserveMethod( string pageName, string pageHandler = null, object routeValues = null, string fragment = null) { if (pageName == null) { throw new ArgumentNullException(nameof(pageName)); } return new RedirectToPageResult( pageName: pageName, pageHandler: pageHandler, routeValues: routeValues, permanent: true, preserveMethod: true, fragment: fragment); } /// /// Returns a file with the specified as content (), /// and the specified as the Content-Type. /// This supports range requests ( or /// if the range is not satisfiable). /// /// The file contents. /// The Content-Type of the file. /// The created for the response. [NonAction] public virtual FileContentResult File(byte[] fileContents, string contentType) => File(fileContents, contentType, fileDownloadName: null); /// /// Returns a file with the specified as content (), /// and the specified as the Content-Type. /// This supports range requests ( or /// if the range is not satisfiable). /// /// The file contents. /// The Content-Type of the file. /// Set to true to enable range requests processing. /// The created for the response. [NonAction] public virtual FileContentResult File(byte[] fileContents, string contentType, bool enableRangeProcessing) => File(fileContents, contentType, fileDownloadName: null, enableRangeProcessing: enableRangeProcessing); /// /// Returns a file with the specified as content (), the /// specified as the Content-Type and the specified as the suggested file name. /// This supports range requests ( or /// if the range is not satisfiable). /// /// The file contents. /// The Content-Type of the file. /// The suggested file name. /// The created for the response. [NonAction] public virtual FileContentResult File(byte[] fileContents, string contentType, string fileDownloadName) => new FileContentResult(fileContents, contentType) { FileDownloadName = fileDownloadName }; /// /// Returns a file with the specified as content (), the /// specified as the Content-Type and the specified as the suggested file name. /// This supports range requests ( or /// if the range is not satisfiable). /// /// The file contents. /// The Content-Type of the file. /// The suggested file name. /// Set to true to enable range requests processing. /// The created for the response. [NonAction] public virtual FileContentResult File(byte[] fileContents, string contentType, string fileDownloadName, bool enableRangeProcessing) => new FileContentResult(fileContents, contentType) { FileDownloadName = fileDownloadName, EnableRangeProcessing = enableRangeProcessing, }; /// /// Returns a file with the specified as content (), /// and the specified as the Content-Type. /// This supports range requests ( or /// if the range is not satisfiable). /// /// The file contents. /// The Content-Type of the file. /// The of when the file was last modified. /// The associated with the file. /// The created for the response. [NonAction] public virtual FileContentResult File(byte[] fileContents, string contentType, DateTimeOffset? lastModified, EntityTagHeaderValue entityTag) { return new FileContentResult(fileContents, contentType) { LastModified = lastModified, EntityTag = entityTag, }; } /// /// Returns a file with the specified as content (), /// and the specified as the Content-Type. /// This supports range requests ( or /// if the range is not satisfiable). /// /// The file contents. /// The Content-Type of the file. /// The of when the file was last modified. /// The associated with the file. /// Set to true to enable range requests processing. /// The created for the response. [NonAction] public virtual FileContentResult File(byte[] fileContents, string contentType, DateTimeOffset? lastModified, EntityTagHeaderValue entityTag, bool enableRangeProcessing) { return new FileContentResult(fileContents, contentType) { LastModified = lastModified, EntityTag = entityTag, EnableRangeProcessing = enableRangeProcessing, }; } /// /// Returns a file with the specified as content (), the /// specified as the Content-Type, and the specified as the suggested file name. /// This supports range requests ( or /// if the range is not satisfiable). /// /// The file contents. /// The Content-Type of the file. /// The suggested file name. /// The of when the file was last modified. /// The associated with the file. /// The created for the response. [NonAction] public virtual FileContentResult File(byte[] fileContents, string contentType, string fileDownloadName, DateTimeOffset? lastModified, EntityTagHeaderValue entityTag) { return new FileContentResult(fileContents, contentType) { LastModified = lastModified, EntityTag = entityTag, FileDownloadName = fileDownloadName, }; } /// /// Returns a file with the specified as content (), the /// specified as the Content-Type, and the specified as the suggested file name. /// This supports range requests ( or /// if the range is not satisfiable). /// /// The file contents. /// The Content-Type of the file. /// The suggested file name. /// The of when the file was last modified. /// The associated with the file. /// Set to true to enable range requests processing. /// The created for the response. [NonAction] public virtual FileContentResult File(byte[] fileContents, string contentType, string fileDownloadName, DateTimeOffset? lastModified, EntityTagHeaderValue entityTag, bool enableRangeProcessing) { return new FileContentResult(fileContents, contentType) { LastModified = lastModified, EntityTag = entityTag, FileDownloadName = fileDownloadName, EnableRangeProcessing = enableRangeProcessing, }; } /// /// Returns a file in the specified (), with the /// specified as the Content-Type. /// This supports range requests ( or /// if the range is not satisfiable). /// /// The with the contents of the file. /// The Content-Type of the file. /// The created for the response. [NonAction] public virtual FileStreamResult File(Stream fileStream, string contentType) => File(fileStream, contentType, fileDownloadName: null); /// /// Returns a file in the specified (), with the /// specified as the Content-Type. /// This supports range requests ( or /// if the range is not satisfiable). /// /// The with the contents of the file. /// The Content-Type of the file. /// Set to true to enable range requests processing. /// The created for the response. [NonAction] public virtual FileStreamResult File(Stream fileStream, string contentType, bool enableRangeProcessing) => File(fileStream, contentType, fileDownloadName: null, enableRangeProcessing: enableRangeProcessing); /// /// Returns a file in the specified () with the /// specified as the Content-Type and the /// specified as the suggested file name. /// This supports range requests ( or /// if the range is not satisfiable). /// /// The with the contents of the file. /// The Content-Type of the file. /// The suggested file name. /// The created for the response. [NonAction] public virtual FileStreamResult File(Stream fileStream, string contentType, string fileDownloadName) => new FileStreamResult(fileStream, contentType) { FileDownloadName = fileDownloadName }; /// /// Returns a file in the specified () with the /// specified as the Content-Type and the /// specified as the suggested file name. /// This supports range requests ( or /// if the range is not satisfiable). /// /// The with the contents of the file. /// The Content-Type of the file. /// The suggested file name. /// Set to true to enable range requests processing. /// The created for the response. [NonAction] public virtual FileStreamResult File(Stream fileStream, string contentType, string fileDownloadName, bool enableRangeProcessing) => new FileStreamResult(fileStream, contentType) { FileDownloadName = fileDownloadName, EnableRangeProcessing = enableRangeProcessing, }; /// /// Returns a file in the specified (), /// and the specified as the Content-Type. /// This supports range requests ( or /// if the range is not satisfiable). /// /// The with the contents of the file. /// The Content-Type of the file. /// The of when the file was last modified. /// The associated with the file. /// The created for the response. [NonAction] public virtual FileStreamResult File(Stream fileStream, string contentType, DateTimeOffset? lastModified, EntityTagHeaderValue entityTag) { return new FileStreamResult(fileStream, contentType) { LastModified = lastModified, EntityTag = entityTag, }; } /// /// Returns a file in the specified (), /// and the specified as the Content-Type. /// This supports range requests ( or /// if the range is not satisfiable). /// /// The with the contents of the file. /// The Content-Type of the file. /// The of when the file was last modified. /// The associated with the file. /// Set to true to enable range requests processing. /// The created for the response. [NonAction] public virtual FileStreamResult File(Stream fileStream, string contentType, DateTimeOffset? lastModified, EntityTagHeaderValue entityTag, bool enableRangeProcessing) { return new FileStreamResult(fileStream, contentType) { LastModified = lastModified, EntityTag = entityTag, EnableRangeProcessing = enableRangeProcessing, }; } /// /// Returns a file in the specified (), the /// specified as the Content-Type, and the specified as the suggested file name. /// This supports range requests ( or /// if the range is not satisfiable). /// /// The with the contents of the file. /// The Content-Type of the file. /// The suggested file name. /// The of when the file was last modified. /// The associated with the file. /// The created for the response. [NonAction] public virtual FileStreamResult File(Stream fileStream, string contentType, string fileDownloadName, DateTimeOffset? lastModified, EntityTagHeaderValue entityTag) { return new FileStreamResult(fileStream, contentType) { LastModified = lastModified, EntityTag = entityTag, FileDownloadName = fileDownloadName, }; } /// /// Returns a file in the specified (), the /// specified as the Content-Type, and the specified as the suggested file name. /// This supports range requests ( or /// if the range is not satisfiable). /// /// The with the contents of the file. /// The Content-Type of the file. /// The suggested file name. /// The of when the file was last modified. /// The associated with the file. /// Set to true to enable range requests processing. /// The created for the response. [NonAction] public virtual FileStreamResult File(Stream fileStream, string contentType, string fileDownloadName, DateTimeOffset? lastModified, EntityTagHeaderValue entityTag, bool enableRangeProcessing) { return new FileStreamResult(fileStream, contentType) { LastModified = lastModified, EntityTag = entityTag, FileDownloadName = fileDownloadName, EnableRangeProcessing = enableRangeProcessing, }; } /// /// Returns the file specified by () with the /// specified as the Content-Type. /// This supports range requests ( or /// if the range is not satisfiable). /// /// The virtual path of the file to be returned. /// The Content-Type of the file. /// The created for the response. [NonAction] public virtual VirtualFileResult File(string virtualPath, string contentType) => File(virtualPath, contentType, fileDownloadName: null); /// /// Returns the file specified by () with the /// specified as the Content-Type. /// This supports range requests ( or /// if the range is not satisfiable). /// /// The virtual path of the file to be returned. /// The Content-Type of the file. /// Set to true to enable range requests processing. /// The created for the response. [NonAction] public virtual VirtualFileResult File(string virtualPath, string contentType, bool enableRangeProcessing) => File(virtualPath, contentType, fileDownloadName: null, enableRangeProcessing: enableRangeProcessing); /// /// Returns the file specified by () with the /// specified as the Content-Type and the /// specified as the suggested file name. /// This supports range requests ( or /// if the range is not satisfiable). /// /// The virtual path of the file to be returned. /// The Content-Type of the file. /// The suggested file name. /// The created for the response. [NonAction] public virtual VirtualFileResult File(string virtualPath, string contentType, string fileDownloadName) => new VirtualFileResult(virtualPath, contentType) { FileDownloadName = fileDownloadName }; /// /// Returns the file specified by () with the /// specified as the Content-Type and the /// specified as the suggested file name. /// This supports range requests ( or /// if the range is not satisfiable). /// /// The virtual path of the file to be returned. /// The Content-Type of the file. /// The suggested file name. /// Set to true to enable range requests processing. /// The created for the response. [NonAction] public virtual VirtualFileResult File(string virtualPath, string contentType, string fileDownloadName, bool enableRangeProcessing) => new VirtualFileResult(virtualPath, contentType) { FileDownloadName = fileDownloadName, EnableRangeProcessing = enableRangeProcessing, }; /// /// Returns the file specified by (), and the /// specified as the Content-Type. /// This supports range requests ( or /// if the range is not satisfiable). /// /// The virtual path of the file to be returned. /// The Content-Type of the file. /// The of when the file was last modified. /// The associated with the file. /// The created for the response. [NonAction] public virtual VirtualFileResult File(string virtualPath, string contentType, DateTimeOffset? lastModified, EntityTagHeaderValue entityTag) { return new VirtualFileResult(virtualPath, contentType) { LastModified = lastModified, EntityTag = entityTag, }; } /// /// Returns the file specified by (), and the /// specified as the Content-Type. /// This supports range requests ( or /// if the range is not satisfiable). /// /// The virtual path of the file to be returned. /// The Content-Type of the file. /// The of when the file was last modified. /// The associated with the file. /// Set to true to enable range requests processing. /// The created for the response. [NonAction] public virtual VirtualFileResult File(string virtualPath, string contentType, DateTimeOffset? lastModified, EntityTagHeaderValue entityTag, bool enableRangeProcessing) { return new VirtualFileResult(virtualPath, contentType) { LastModified = lastModified, EntityTag = entityTag, EnableRangeProcessing = enableRangeProcessing, }; } /// /// Returns the file specified by (), the /// specified as the Content-Type, and the specified as the suggested file name. /// This supports range requests ( or /// if the range is not satisfiable). /// /// The virtual path of the file to be returned. /// The Content-Type of the file. /// The suggested file name. /// The of when the file was last modified. /// The associated with the file. /// The created for the response. [NonAction] public virtual VirtualFileResult File(string virtualPath, string contentType, string fileDownloadName, DateTimeOffset? lastModified, EntityTagHeaderValue entityTag) { return new VirtualFileResult(virtualPath, contentType) { LastModified = lastModified, EntityTag = entityTag, FileDownloadName = fileDownloadName, }; } /// /// Returns the file specified by (), the /// specified as the Content-Type, and the specified as the suggested file name. /// This supports range requests ( or /// if the range is not satisfiable). /// /// The virtual path of the file to be returned. /// The Content-Type of the file. /// The suggested file name. /// The of when the file was last modified. /// The associated with the file. /// Set to true to enable range requests processing. /// The created for the response. [NonAction] public virtual VirtualFileResult File(string virtualPath, string contentType, string fileDownloadName, DateTimeOffset? lastModified, EntityTagHeaderValue entityTag, bool enableRangeProcessing) { return new VirtualFileResult(virtualPath, contentType) { LastModified = lastModified, EntityTag = entityTag, FileDownloadName = fileDownloadName, EnableRangeProcessing = enableRangeProcessing, }; } /// /// Returns the file specified by () with the /// specified as the Content-Type. /// This supports range requests ( or /// if the range is not satisfiable). /// /// The path to the file. The path must be an absolute path. /// The Content-Type of the file. /// The created for the response. [NonAction] public virtual PhysicalFileResult PhysicalFile(string physicalPath, string contentType) => PhysicalFile(physicalPath, contentType, fileDownloadName: null); /// /// Returns the file specified by () with the /// specified as the Content-Type. /// This supports range requests ( or /// if the range is not satisfiable). /// /// The path to the file. The path must be an absolute path. /// The Content-Type of the file. /// Set to true to enable range requests processing. /// The created for the response. [NonAction] public virtual PhysicalFileResult PhysicalFile(string physicalPath, string contentType, bool enableRangeProcessing) => PhysicalFile(physicalPath, contentType, fileDownloadName: null, enableRangeProcessing: enableRangeProcessing); /// /// Returns the file specified by () with the /// specified as the Content-Type and the /// specified as the suggested file name. /// This supports range requests ( or /// if the range is not satisfiable). /// /// The path to the file. The path must be an absolute path. /// The Content-Type of the file. /// The suggested file name. /// The created for the response. [NonAction] public virtual PhysicalFileResult PhysicalFile( string physicalPath, string contentType, string fileDownloadName) => new PhysicalFileResult(physicalPath, contentType) { FileDownloadName = fileDownloadName }; /// /// Returns the file specified by () with the /// specified as the Content-Type and the /// specified as the suggested file name. /// This supports range requests ( or /// if the range is not satisfiable). /// /// The path to the file. The path must be an absolute path. /// The Content-Type of the file. /// The suggested file name. /// Set to true to enable range requests processing. /// The created for the response. [NonAction] public virtual PhysicalFileResult PhysicalFile( string physicalPath, string contentType, string fileDownloadName, bool enableRangeProcessing) => new PhysicalFileResult(physicalPath, contentType) { FileDownloadName = fileDownloadName, EnableRangeProcessing = enableRangeProcessing, }; /// /// Returns the file specified by (), and /// the specified as the Content-Type. /// This supports range requests ( or /// if the range is not satisfiable). /// /// The path to the file. The path must be an absolute path. /// The Content-Type of the file. /// The of when the file was last modified. /// The associated with the file. /// The created for the response. [NonAction] public virtual PhysicalFileResult PhysicalFile(string physicalPath, string contentType, DateTimeOffset? lastModified, EntityTagHeaderValue entityTag) { return new PhysicalFileResult(physicalPath, contentType) { LastModified = lastModified, EntityTag = entityTag, }; } /// /// Returns the file specified by (), and /// the specified as the Content-Type. /// This supports range requests ( or /// if the range is not satisfiable). /// /// The path to the file. The path must be an absolute path. /// The Content-Type of the file. /// The of when the file was last modified. /// The associated with the file. /// Set to true to enable range requests processing. /// The created for the response. [NonAction] public virtual PhysicalFileResult PhysicalFile(string physicalPath, string contentType, DateTimeOffset? lastModified, EntityTagHeaderValue entityTag, bool enableRangeProcessing) { return new PhysicalFileResult(physicalPath, contentType) { LastModified = lastModified, EntityTag = entityTag, EnableRangeProcessing = enableRangeProcessing, }; } /// /// Returns the file specified by (), the /// specified as the Content-Type, and the specified as the suggested file name. /// This supports range requests ( or /// if the range is not satisfiable). /// /// The path to the file. The path must be an absolute path. /// The Content-Type of the file. /// The suggested file name. /// The of when the file was last modified. /// The associated with the file. /// The created for the response. [NonAction] public virtual PhysicalFileResult PhysicalFile(string physicalPath, string contentType, string fileDownloadName, DateTimeOffset? lastModified, EntityTagHeaderValue entityTag) { return new PhysicalFileResult(physicalPath, contentType) { LastModified = lastModified, EntityTag = entityTag, FileDownloadName = fileDownloadName, }; } /// /// Returns the file specified by (), the /// specified as the Content-Type, and the specified as the suggested file name. /// This supports range requests ( or /// if the range is not satisfiable). /// /// The path to the file. The path must be an absolute path. /// The Content-Type of the file. /// The suggested file name. /// The of when the file was last modified. /// The associated with the file. /// Set to true to enable range requests processing. /// The created for the response. [NonAction] public virtual PhysicalFileResult PhysicalFile(string physicalPath, string contentType, string fileDownloadName, DateTimeOffset? lastModified, EntityTagHeaderValue entityTag, bool enableRangeProcessing) { return new PhysicalFileResult(physicalPath, contentType) { LastModified = lastModified, EntityTag = entityTag, FileDownloadName = fileDownloadName, EnableRangeProcessing = enableRangeProcessing, }; } /// /// Creates an that produces an response. /// /// The created for the response. [NonAction] public virtual UnauthorizedResult Unauthorized() => new UnauthorizedResult(); /// /// Creates an that produces a response. /// /// The created for the response. [NonAction] public virtual NotFoundResult NotFound() => new NotFoundResult(); /// /// Creates an that produces a response. /// /// The created for the response. [NonAction] public virtual NotFoundObjectResult NotFound(object value) => new NotFoundObjectResult(value); /// /// Creates an that produces a response. /// /// The created for the response. [NonAction] public virtual BadRequestResult BadRequest() => new BadRequestResult(); /// /// Creates an that produces a response. /// /// An error object to be returned to the client. /// The created for the response. [NonAction] public virtual BadRequestObjectResult BadRequest(object error) => new BadRequestObjectResult(error); /// /// Creates an that produces a response. /// /// The containing errors to be returned to the client. /// The created for the response. [NonAction] public virtual BadRequestObjectResult BadRequest(ModelStateDictionary modelState) { if (modelState == null) { throw new ArgumentNullException(nameof(modelState)); } return new BadRequestObjectResult(modelState); } /// /// Creates an that produces a response. /// /// The created for the response. [NonAction] public virtual UnprocessableEntityResult UnprocessableEntity() { return new UnprocessableEntityResult(); } /// /// Creates an that produces a response. /// /// An error object to be returned to the client. /// The created for the response. [NonAction] public virtual UnprocessableEntityObjectResult UnprocessableEntity(object error) { return new UnprocessableEntityObjectResult(error); } /// /// Creates an that produces a response. /// /// The containing errors to be returned to the client. /// The created for the response. [NonAction] public virtual UnprocessableEntityObjectResult UnprocessableEntity(ModelStateDictionary modelState) { if (modelState == null) { throw new ArgumentNullException(nameof(modelState)); } return new UnprocessableEntityObjectResult(modelState); } /// /// Creates an that produces a response. /// /// The created for the response. [NonAction] public virtual ConflictResult Conflict() => new ConflictResult(); /// /// Creates an that produces a response. /// /// Contains errors to be returned to the client. /// The created for the response. [NonAction] public virtual ConflictObjectResult Conflict(object error) => new ConflictObjectResult(error); /// /// Creates an that produces a response. /// /// The containing errors to be returned to the client. /// The created for the response. [NonAction] public virtual ConflictObjectResult Conflict(ModelStateDictionary modelState) => new ConflictObjectResult(modelState); /// /// Creates an that produces a response. /// /// The created for the response. [NonAction] public virtual ActionResult ValidationProblem(ValidationProblemDetails descriptor) { if (descriptor == null) { throw new ArgumentNullException(nameof(descriptor)); } return new BadRequestObjectResult(descriptor); } /// /// Creates an that produces a response. /// /// The created for the response. [NonAction] public virtual ActionResult ValidationProblem(ModelStateDictionary modelStateDictionary) { if (modelStateDictionary == null) { throw new ArgumentNullException(nameof(modelStateDictionary)); } var validationProblem = new ValidationProblemDetails(modelStateDictionary); return new BadRequestObjectResult(validationProblem); } /// /// Creates an that produces a response /// with validation errors from . /// /// The created for the response. [NonAction] public virtual ActionResult ValidationProblem() { var validationProblem = new ValidationProblemDetails(ModelState); return new BadRequestObjectResult(validationProblem); } /// /// Creates a object that produces a response. /// /// The URI at which the content has been created. /// The content value to format in the entity body. /// The created for the response. [NonAction] public virtual CreatedResult Created(string uri, object value) { if (uri == null) { throw new ArgumentNullException(nameof(uri)); } return new CreatedResult(uri, value); } /// /// Creates a object that produces a response. /// /// The URI at which the content has been created. /// The content value to format in the entity body. /// The created for the response. [NonAction] public virtual CreatedResult Created(Uri uri, object value) { if (uri == null) { throw new ArgumentNullException(nameof(uri)); } return new CreatedResult(uri, value); } /// /// Creates a object that produces a response. /// /// The name of the action to use for generating the URL. /// The content value to format in the entity body. /// The created for the response. [NonAction] public virtual CreatedAtActionResult CreatedAtAction(string actionName, object value) => CreatedAtAction(actionName, routeValues: null, value: value); /// /// Creates a object that produces a response. /// /// The name of the action to use for generating the URL. /// The route data to use for generating the URL. /// The content value to format in the entity body. /// The created for the response. [NonAction] public virtual CreatedAtActionResult CreatedAtAction(string actionName, object routeValues, object value) => CreatedAtAction(actionName, controllerName: null, routeValues: routeValues, value: value); /// /// Creates a object that produces a response. /// /// The name of the action to use for generating the URL. /// The name of the controller to use for generating the URL. /// The route data to use for generating the URL. /// The content value to format in the entity body. /// The created for the response. [NonAction] public virtual CreatedAtActionResult CreatedAtAction( string actionName, string controllerName, object routeValues, object value) => new CreatedAtActionResult(actionName, controllerName, routeValues, value); /// /// Creates a object that produces a response. /// /// The name of the route to use for generating the URL. /// The content value to format in the entity body. /// The created for the response. [NonAction] public virtual CreatedAtRouteResult CreatedAtRoute(string routeName, object value) => CreatedAtRoute(routeName, routeValues: null, value: value); /// /// Creates a object that produces a response. /// /// The route data to use for generating the URL. /// The content value to format in the entity body. /// The created for the response. [NonAction] public virtual CreatedAtRouteResult CreatedAtRoute(object routeValues, object value) => CreatedAtRoute(routeName: null, routeValues: routeValues, value: value); /// /// Creates a object that produces a response. /// /// The name of the route to use for generating the URL. /// The route data to use for generating the URL. /// The content value to format in the entity body. /// The created for the response. [NonAction] public virtual CreatedAtRouteResult CreatedAtRoute(string routeName, object routeValues, object value) => new CreatedAtRouteResult(routeName, routeValues, value); /// /// Creates a object that produces an response. /// /// The created for the response. [NonAction] public virtual AcceptedResult Accepted() => new AcceptedResult(); /// /// Creates a object that produces an response. /// /// The optional content value to format in the entity body; may be null. /// The created for the response. [NonAction] public virtual AcceptedResult Accepted(object value) => new AcceptedResult(location: null, value: value); /// /// Creates a object that produces an response. /// /// The optional URI with the location at which the status of requested content can be monitored. /// May be null. /// The created for the response. [NonAction] public virtual AcceptedResult Accepted(Uri uri) { if (uri == null) { throw new ArgumentNullException(nameof(uri)); } return new AcceptedResult(locationUri: uri, value: null); } /// /// Creates a object that produces an response. /// /// The optional URI with the location at which the status of requested content can be monitored. /// May be null. /// The created for the response. [NonAction] public virtual AcceptedResult Accepted(string uri) => new AcceptedResult(location: uri, value: null); /// /// Creates a object that produces an response. /// /// The URI with the location at which the status of requested content can be monitored. /// The optional content value to format in the entity body; may be null. /// The created for the response. [NonAction] public virtual AcceptedResult Accepted(string uri, object value) => new AcceptedResult(uri, value); /// /// Creates a object that produces an response. /// /// The URI with the location at which the status of requested content can be monitored. /// The optional content value to format in the entity body; may be null. /// The created for the response. [NonAction] public virtual AcceptedResult Accepted(Uri uri, object value) { if (uri == null) { throw new ArgumentNullException(nameof(uri)); } return new AcceptedResult(locationUri: uri, value: value); } /// /// Creates a object that produces an response. /// /// The name of the action to use for generating the URL. /// The created for the response. [NonAction] public virtual AcceptedAtActionResult AcceptedAtAction(string actionName) => AcceptedAtAction(actionName, routeValues: null, value: null); /// /// Creates a object that produces an response. /// /// The name of the action to use for generating the URL. /// The name of the controller to use for generating the URL. /// The created for the response. [NonAction] public virtual AcceptedAtActionResult AcceptedAtAction(string actionName, string controllerName) => AcceptedAtAction(actionName, controllerName, routeValues: null, value: null); /// /// Creates a object that produces an response. /// /// The name of the action to use for generating the URL. /// The optional content value to format in the entity body; may be null. /// The created for the response. [NonAction] public virtual AcceptedAtActionResult AcceptedAtAction(string actionName, object value) => AcceptedAtAction(actionName, routeValues: null, value: value); /// /// Creates a object that produces an response. /// /// The name of the action to use for generating the URL. /// The name of the controller to use for generating the URL. /// The route data to use for generating the URL. /// The created for the response. [NonAction] public virtual AcceptedAtActionResult AcceptedAtAction(string actionName, string controllerName, object routeValues) => AcceptedAtAction(actionName, controllerName, routeValues, value: null); /// /// Creates a object that produces an response. /// /// The name of the action to use for generating the URL. /// The route data to use for generating the URL. /// The optional content value to format in the entity body; may be null. /// The created for the response. [NonAction] public virtual AcceptedAtActionResult AcceptedAtAction(string actionName, object routeValues, object value) => AcceptedAtAction(actionName, controllerName: null, routeValues: routeValues, value: value); /// /// Creates a object that produces an response. /// /// The name of the action to use for generating the URL. /// The name of the controller to use for generating the URL. /// The route data to use for generating the URL. /// The optional content value to format in the entity body; may be null. /// The created for the response. [NonAction] public virtual AcceptedAtActionResult AcceptedAtAction( string actionName, string controllerName, object routeValues, object value) => new AcceptedAtActionResult(actionName, controllerName, routeValues, value); /// /// Creates a object that produces an response. /// /// The route data to use for generating the URL. /// The created for the response. [NonAction] public virtual AcceptedAtRouteResult AcceptedAtRoute(object routeValues) => AcceptedAtRoute(routeName: null, routeValues: routeValues, value: null); /// /// Creates a object that produces an response. /// /// The name of the route to use for generating the URL. /// The created for the response. [NonAction] public virtual AcceptedAtRouteResult AcceptedAtRoute(string routeName) => AcceptedAtRoute(routeName, routeValues: null, value: null); /// /// Creates a object that produces an response. /// /// The name of the route to use for generating the URL. ///The route data to use for generating the URL. /// The created for the response. [NonAction] public virtual AcceptedAtRouteResult AcceptedAtRoute(string routeName, object routeValues) => AcceptedAtRoute(routeName, routeValues, value: null); /// /// Creates a object that produces an response. /// /// The route data to use for generating the URL. /// The optional content value to format in the entity body; may be null. /// The created for the response. [NonAction] public virtual AcceptedAtRouteResult AcceptedAtRoute(object routeValues, object value) => AcceptedAtRoute(routeName: null, routeValues: routeValues, value: value); /// /// Creates a object that produces an response. /// /// The name of the route to use for generating the URL. /// The route data to use for generating the URL. /// The optional content value to format in the entity body; may be null. /// The created for the response. [NonAction] public virtual AcceptedAtRouteResult AcceptedAtRoute(string routeName, object routeValues, object value) => new AcceptedAtRouteResult(routeName, routeValues, value); /// /// Creates a . /// /// The created for the response. /// /// The behavior of this method depends on the in use. /// and /// are among likely status results. /// [NonAction] public virtual ChallengeResult Challenge() => new ChallengeResult(); /// /// Creates a with the specified authentication schemes. /// /// The authentication schemes to challenge. /// The created for the response. /// /// The behavior of this method depends on the in use. /// and /// are among likely status results. /// [NonAction] public virtual ChallengeResult Challenge(params string[] authenticationSchemes) => new ChallengeResult(authenticationSchemes); /// /// Creates a with the specified . /// /// used to perform the authentication /// challenge. /// The created for the response. /// /// The behavior of this method depends on the in use. /// and /// are among likely status results. /// [NonAction] public virtual ChallengeResult Challenge(AuthenticationProperties properties) => new ChallengeResult(properties); /// /// Creates a with the specified authentication schemes and /// . /// /// used to perform the authentication /// challenge. /// The authentication schemes to challenge. /// The created for the response. /// /// The behavior of this method depends on the in use. /// and /// are among likely status results. /// [NonAction] public virtual ChallengeResult Challenge( AuthenticationProperties properties, params string[] authenticationSchemes) => new ChallengeResult(authenticationSchemes, properties); /// /// Creates a ( by default). /// /// The created for the response. /// /// Some authentication schemes, such as cookies, will convert to /// a redirect to show a login page. /// [NonAction] public virtual ForbidResult Forbid() => new ForbidResult(); /// /// Creates a ( by default) with the /// specified authentication schemes. /// /// The authentication schemes to challenge. /// The created for the response. /// /// Some authentication schemes, such as cookies, will convert to /// a redirect to show a login page. /// [NonAction] public virtual ForbidResult Forbid(params string[] authenticationSchemes) => new ForbidResult(authenticationSchemes); /// /// Creates a ( by default) with the /// specified . /// /// used to perform the authentication /// challenge. /// The created for the response. /// /// Some authentication schemes, such as cookies, will convert to /// a redirect to show a login page. /// [NonAction] public virtual ForbidResult Forbid(AuthenticationProperties properties) => new ForbidResult(properties); /// /// Creates a ( by default) with the /// specified authentication schemes and . /// /// used to perform the authentication /// challenge. /// The authentication schemes to challenge. /// The created for the response. /// /// Some authentication schemes, such as cookies, will convert to /// a redirect to show a login page. /// [NonAction] public virtual ForbidResult Forbid(AuthenticationProperties properties, params string[] authenticationSchemes) => new ForbidResult(authenticationSchemes, properties); /// /// Creates a with the specified authentication scheme. /// /// The containing the user claims. /// The authentication scheme to use for the sign-in operation. /// The created for the response. [NonAction] public virtual SignInResult SignIn(ClaimsPrincipal principal, string authenticationScheme) => new SignInResult(authenticationScheme, principal); /// /// Creates a with the specified authentication scheme and /// . /// /// The containing the user claims. /// used to perform the sign-in operation. /// The authentication scheme to use for the sign-in operation. /// The created for the response. [NonAction] public virtual SignInResult SignIn( ClaimsPrincipal principal, AuthenticationProperties properties, string authenticationScheme) => new SignInResult(authenticationScheme, principal, properties); /// /// Creates a with the specified authentication schemes. /// /// The authentication schemes to use for the sign-out operation. /// The created for the response. [NonAction] public virtual SignOutResult SignOut(params string[] authenticationSchemes) => new SignOutResult(authenticationSchemes); /// /// Creates a with the specified authentication schemes and /// . /// /// used to perform the sign-out operation. /// The authentication scheme to use for the sign-out operation. /// The created for the response. [NonAction] public virtual SignOutResult SignOut(AuthenticationProperties properties, params string[] authenticationSchemes) => new SignOutResult(authenticationSchemes, properties); /// /// Updates the specified instance using values from the controller's current /// . /// /// The type of the model object. /// The model instance to update. /// A that on completion returns true if the update is successful. [NonAction] public virtual Task TryUpdateModelAsync( TModel model) where TModel : class { if (model == null) { throw new ArgumentNullException(nameof(model)); } return TryUpdateModelAsync(model, prefix: string.Empty); } /// /// Updates the specified instance using values from the controller's current /// and a . /// /// The type of the model object. /// The model instance to update. /// The prefix to use when looking up values in the current . /// /// A that on completion returns true if the update is successful. [NonAction] public virtual async Task TryUpdateModelAsync( TModel model, string prefix) where TModel : class { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (prefix == null) { throw new ArgumentNullException(nameof(prefix)); } var valueProvider = await CompositeValueProvider.CreateAsync(ControllerContext); return await TryUpdateModelAsync(model, prefix, valueProvider); } /// /// Updates the specified instance using the and a /// . /// /// The type of the model object. /// The model instance to update. /// The prefix to use when looking up values in the . /// /// The used for looking up values. /// A that on completion returns true if the update is successful. [NonAction] public virtual Task TryUpdateModelAsync( TModel model, string prefix, IValueProvider valueProvider) where TModel : class { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (prefix == null) { throw new ArgumentNullException(nameof(prefix)); } if (valueProvider == null) { throw new ArgumentNullException(nameof(valueProvider)); } return ModelBindingHelper.TryUpdateModelAsync( model, prefix, ControllerContext, MetadataProvider, ModelBinderFactory, valueProvider, ObjectValidator); } /// /// Updates the specified instance using values from the controller's current /// and a . /// /// The type of the model object. /// The model instance to update. /// The prefix to use when looking up values in the current . /// /// (s) which represent top-level properties /// which need to be included for the current model. /// A that on completion returns true if the update is successful. [NonAction] public async Task TryUpdateModelAsync( TModel model, string prefix, params Expression>[] includeExpressions) where TModel : class { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (includeExpressions == null) { throw new ArgumentNullException(nameof(includeExpressions)); } var valueProvider = await CompositeValueProvider.CreateAsync(ControllerContext); return await ModelBindingHelper.TryUpdateModelAsync( model, prefix, ControllerContext, MetadataProvider, ModelBinderFactory, valueProvider, ObjectValidator, includeExpressions); } /// /// Updates the specified instance using values from the controller's current /// and a . /// /// The type of the model object. /// The model instance to update. /// The prefix to use when looking up values in the current . /// /// A predicate which can be used to filter properties at runtime. /// A that on completion returns true if the update is successful. [NonAction] public async Task TryUpdateModelAsync( TModel model, string prefix, Func propertyFilter) where TModel : class { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (propertyFilter == null) { throw new ArgumentNullException(nameof(propertyFilter)); } var valueProvider = await CompositeValueProvider.CreateAsync(ControllerContext); return await ModelBindingHelper.TryUpdateModelAsync( model, prefix, ControllerContext, MetadataProvider, ModelBinderFactory, valueProvider, ObjectValidator, propertyFilter); } /// /// Updates the specified instance using the and a /// . /// /// The type of the model object. /// The model instance to update. /// The prefix to use when looking up values in the . /// /// The used for looking up values. /// (s) which represent top-level properties /// which need to be included for the current model. /// A that on completion returns true if the update is successful. [NonAction] public Task TryUpdateModelAsync( TModel model, string prefix, IValueProvider valueProvider, params Expression>[] includeExpressions) where TModel : class { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (valueProvider == null) { throw new ArgumentNullException(nameof(valueProvider)); } if (includeExpressions == null) { throw new ArgumentNullException(nameof(includeExpressions)); } return ModelBindingHelper.TryUpdateModelAsync( model, prefix, ControllerContext, MetadataProvider, ModelBinderFactory, valueProvider, ObjectValidator, includeExpressions); } /// /// Updates the specified instance using the and a /// . /// /// The type of the model object. /// The model instance to update. /// The prefix to use when looking up values in the . /// /// The used for looking up values. /// A predicate which can be used to filter properties at runtime. /// A that on completion returns true if the update is successful. [NonAction] public Task TryUpdateModelAsync( TModel model, string prefix, IValueProvider valueProvider, Func propertyFilter) where TModel : class { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (valueProvider == null) { throw new ArgumentNullException(nameof(valueProvider)); } if (propertyFilter == null) { throw new ArgumentNullException(nameof(propertyFilter)); } return ModelBindingHelper.TryUpdateModelAsync( model, prefix, ControllerContext, MetadataProvider, ModelBinderFactory, valueProvider, ObjectValidator, propertyFilter); } /// /// Updates the specified instance using values from the controller's current /// and a . /// /// The model instance to update. /// The type of model instance to update. /// The prefix to use when looking up values in the current . /// /// A that on completion returns true if the update is successful. [NonAction] public virtual async Task TryUpdateModelAsync( object model, Type modelType, string prefix) { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (modelType == null) { throw new ArgumentNullException(nameof(modelType)); } var valueProvider = await CompositeValueProvider.CreateAsync(ControllerContext); return await ModelBindingHelper.TryUpdateModelAsync( model, modelType, prefix, ControllerContext, MetadataProvider, ModelBinderFactory, valueProvider, ObjectValidator); } /// /// Updates the specified instance using the and a /// . /// /// The model instance to update. /// The type of model instance to update. /// The prefix to use when looking up values in the . /// /// The used for looking up values. /// A predicate which can be used to filter properties at runtime. /// A that on completion returns true if the update is successful. [NonAction] public Task TryUpdateModelAsync( object model, Type modelType, string prefix, IValueProvider valueProvider, Func propertyFilter) { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (modelType == null) { throw new ArgumentNullException(nameof(modelType)); } if (valueProvider == null) { throw new ArgumentNullException(nameof(valueProvider)); } if (propertyFilter == null) { throw new ArgumentNullException(nameof(propertyFilter)); } return ModelBindingHelper.TryUpdateModelAsync( model, modelType, prefix, ControllerContext, MetadataProvider, ModelBinderFactory, valueProvider, ObjectValidator, propertyFilter); } /// /// Validates the specified instance. /// /// The model to validate. /// true if the is valid; false otherwise. [NonAction] public virtual bool TryValidateModel( object model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } return TryValidateModel(model, prefix: null); } /// /// Validates the specified instance. /// /// The model to validate. /// The key to use when looking up information in . /// /// true if the is valid;false otherwise. [NonAction] public virtual bool TryValidateModel( object model, string prefix) { if (model == null) { throw new ArgumentNullException(nameof(model)); } ObjectValidator.Validate( ControllerContext, validationState: null, prefix: prefix ?? string.Empty, model: model); return ModelState.IsValid; } } }