// 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.AspNet.Http; using Microsoft.Framework.Internal; using Microsoft.Net.Http.Headers; namespace Microsoft.AspNet.Mvc { /// /// An that returns a Created (201) response with a Location header. /// public class CreatedResult : ObjectResult { private string _location; /// /// Initializes a new instance of the class with the values /// provided. /// /// The location at which the content has been created. /// The value to format in the entity body. public CreatedResult([NotNull] string location, object value) : base(value) { Location = location; StatusCode = StatusCodes.Status201Created; } /// /// Gets or sets the location at which the content has been created. /// public string Location { get { return _location; } set { if (value == null) { throw new ArgumentNullException(nameof(value)); } _location = value; } } /// protected override void OnFormatting([NotNull] ActionContext context) { context.HttpContext.Response.Headers[HeaderNames.Location] = Location; } } }