Added ObjectResult implementation for Unauthorized response

This commit is contained in:
Zbginiew Dobras 2018-06-25 11:26:56 +02:00 committed by Pranav K
parent 133d49c57e
commit f6befb9ed3
2 changed files with 33 additions and 0 deletions

View File

@ -1704,6 +1704,14 @@ namespace Microsoft.AspNetCore.Mvc
public virtual UnauthorizedResult Unauthorized()
=> new UnauthorizedResult();
/// <summary>
/// Creates an <see cref="UnauthorizedObjectResult"/> that produces a <see cref="StatusCodes.Status401Unauthorized"/> response.
/// </summary>
/// <returns>The created <see cref="UnauthorizedObjectResult"/> for the response.</returns>
[NonAction]
public virtual UnauthorizedObjectResult Unauthorized(object value)
=> new UnauthorizedObjectResult(value);
/// <summary>
/// Creates an <see cref="NotFoundResult"/> that produces a <see cref="StatusCodes.Status404NotFound"/> response.
/// </summary>

View File

@ -0,0 +1,25 @@
// 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 Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Infrastructure;
namespace Microsoft.AspNetCore.Mvc
{
/// <summary>
/// An <see cref="ObjectResult"/> that when executed will produce a Unauthorized (401) response.
/// </summary>
[DefaultStatusCode(DefaultStatusCode)]
public class UnauthorizedObjectResult : ObjectResult
{
private const int DefaultStatusCode = StatusCodes.Status401Unauthorized;
/// <summary>
/// Creates a new <see cref="UnauthorizedObjectResult"/> instance.
/// </summary>
public UnauthorizedObjectResult(object value) : base(value)
{
StatusCode = DefaultStatusCode;
}
}
}