diff --git a/src/Microsoft.AspNet.Mvc.Core/CreatedResult.cs b/src/Microsoft.AspNet.Mvc.Core/CreatedResult.cs index 02ac39c398..dc08ad9b2a 100644 --- a/src/Microsoft.AspNet.Mvc.Core/CreatedResult.cs +++ b/src/Microsoft.AspNet.Mvc.Core/CreatedResult.cs @@ -29,6 +29,27 @@ namespace Microsoft.AspNet.Mvc StatusCode = StatusCodes.Status201Created; } + /// + /// 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] Uri location, object value) + : base(value) + { + if (location.IsAbsoluteUri) + { + Location = location.AbsoluteUri; + } + else + { + Location = location.GetComponents(UriComponents.SerializationInfoString, UriFormat.UriEscaped); + } + + StatusCode = StatusCodes.Status201Created; + } + /// /// Gets or sets the location at which the content has been created. /// diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Controller.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Controller.cs index 3066cfea15..9784d5d4c2 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Controller.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Controller.cs @@ -941,17 +941,13 @@ namespace Microsoft.AspNet.Mvc [NonAction] public virtual CreatedResult Created([NotNull] Uri uri, object value) { - string location; - if (uri.IsAbsoluteUri) + var disposableValue = value as IDisposable; + if (disposableValue != null) { - location = uri.AbsoluteUri; + Response.RegisterForDispose(disposableValue); } - else - { - location = uri.GetComponents(UriComponents.SerializationInfoString, UriFormat.UriEscaped); - } - - return Created(location, value); + + return new CreatedResult(uri, value); } ///