Class ForbiddenResult
- Namespace
- Cuemon.AspNetCore.Mvc
- Assembly
- Cuemon.AspNetCore.Mvc.dll
An ActionResult that returns a Forbidden (403) response.
public class ForbiddenResult : StatusCodeResult, IClientErrorActionResult, IStatusCodeActionResult, IActionResult
- Inheritance
-
ForbiddenResult
- Implements
- Inherited Members
Examples
The following example shows how can return the default 403 status code or a different client-error code when you want to hide the existence of a protected resource.
using System;
using Cuemon.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;
namespace MyApp.Examples;
public static class ForbiddenResultExample
{
public static void Demonstrate()
{
var forbidden = new ForbiddenResult();
var disguised = new ForbiddenResult(StatusCodes.Status404NotFound);
Console.WriteLine(forbidden.StatusCode);
Console.WriteLine(disguised.StatusCode);
}
}
Constructors
ForbiddenResult(int)
Initializes a new instance of the ForbiddenResult class.
public ForbiddenResult(int statusCode = 403)
Parameters
statusCodeintThe HTTP status code of the response which has to be in the 400-499 range. Default is 403, but for security reasons you may wish to "hide" this with another, e.g., 400, 404 or whatever fits your strategy.