Class UnauthorizedException
- Namespace
- Cuemon.AspNetCore.Http
- Assembly
- 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()
{
var exception = new UnauthorizedException(
"The request is missing a valid bearer token.",
new InvalidOperationException("Token validation failed."));
Console.WriteLine(exception.StatusCode);
Console.WriteLine(exception.InnerException?.GetType().Name);
}
}
Constructors
UnauthorizedException()
Initializes a new instance of the UnauthorizedException class.
public UnauthorizedException()
UnauthorizedException(Exception)
Initializes a new instance of the UnauthorizedException class.
public UnauthorizedException(Exception innerException)
Parameters
innerExceptionExceptionThe exception that is the cause of the current exception.
UnauthorizedException(string, Exception)
Initializes a new instance of the UnauthorizedException class.
public UnauthorizedException(string message, Exception innerException = null)
Parameters
messagestringThe message that describes the HTTP status code.
innerExceptionExceptionThe exception that is the cause of the current exception.