// 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 Microsoft.AspNetCore.Mvc.Internal; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; namespace Microsoft.AspNetCore.Mvc { /// /// Represents an that when executed will /// produce an HTTP response with the given response status code. /// public class StatusCodeResult : ActionResult { /// /// Initializes a new instance of the class /// with the given . /// /// The HTTP status code of the response. public StatusCodeResult(int statusCode) { StatusCode = statusCode; } /// /// Gets the HTTP status code. /// public int StatusCode { get; } /// public override void ExecuteResult(ActionContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var factory = context.HttpContext.RequestServices.GetRequiredService(); var logger = factory.CreateLogger(); logger.HttpStatusCodeResultExecuting(StatusCode); context.HttpContext.Response.StatusCode = StatusCode; } } }