Table of Contents

UnauthorizedException Class

Definition

Namespace
Cuemon.AspNetCore.Http
Assemblies
Cuemon.AspNetCore.dll
Source
src/Cuemon.AspNetCore/Http/UnauthorizedException.cs

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.

// Program.cs
using System;
using Cuemon.AspNetCore.Http;

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.

See Also