UnauthorizedException Class
Definition
- Namespace
- Cuemon.AspNetCore.Http
- Assemblies
- Cuemon.AspNetCore.dll
The exception that is thrown when the requirements of an HTTP WWW-Authenticate header is not meet.
public class UnauthorizedException : HttpStatusCodeException, ISerializable
- Inheritance
-
UnauthorizedException
- Implements
- Inherited Members
Examples
The following example demonstrates how to use UnauthorizedException to indicate missing or invalid authentication.
using System;
namespace Cuemon.AspNetCore.Http;
public static class UnauthorizedExceptionExample
{
public static void Demonstrate()
{
const string authenticationScheme = "Bearer";
var exception = new UnauthorizedException(
$"The request is missing a valid {authenticationScheme} token.",
new InvalidOperationException("Token validation failed."));
Console.WriteLine(exception.StatusCode);
Console.WriteLine(exception.Message);
Console.WriteLine(exception.InnerException?.Message);
}
}
Constructors
| Name | Description |
|---|---|
| UnauthorizedException() | Initializes a new instance of the UnauthorizedException class. |
| UnauthorizedException(Exception) | Initializes a new instance of the UnauthorizedException class. |
| UnauthorizedException(string, Exception) | Initializes a new instance of the UnauthorizedException class. |