.NET exceptions I can throw for Not Authorized or Not Authenticated

authentication, authorization, c#, exception

Solution

Use the C# AuthenticationException or InvalidCredentialException class.

https://learn.microsoft.com/en-us/dotnet/api/system.security.authentication.authenticationexception

Problem

I have parts of code where I want to throw an Exception whenever a user is not authenticated/not authorized. So instead of writing my own NotAuthenticatedException and NotAuthorizedException, I was wondering if there are not already some C# standards for these. I can imagine a lot of programs throw similar Exceptions, and it would not be very useful if everyone 'writes their own wheel' again.

Original source