Class MethodNotAllowedException
- Namespace
- Cuemon.AspNetCore.Http
- Assembly
- Cuemon.AspNetCore.dll
The exception that is thrown when the request method is known by the server but has been disabled and cannot be used.
public class MethodNotAllowedException : HttpStatusCodeException, ISerializable
- Inheritance
-
MethodNotAllowedException
- Implements
- Inherited Members
Examples
The following example demonstrates how to use MethodNotAllowedException when a POST-only endpoint receives a GET request.
using System;
namespace Cuemon.AspNetCore.Http;
public static class MethodNotAllowedExceptionExample
{
public static void Demonstrate()
{
var allowedMethods = string.Join(", ", new[] { "POST", "PUT" });
var exception = new MethodNotAllowedException($"Only {allowedMethods} are supported for /orders.");
Console.WriteLine(exception.Message);
Console.WriteLine(exception.StatusCode);
}
}
Constructors
MethodNotAllowedException()
Initializes a new instance of the MethodNotAllowedException class.
public MethodNotAllowedException()
MethodNotAllowedException(Exception)
Initializes a new instance of the MethodNotAllowedException class.
public MethodNotAllowedException(Exception innerException)
Parameters
innerExceptionExceptionThe exception that is the cause of the current exception.
MethodNotAllowedException(string, Exception)
Initializes a new instance of the MethodNotAllowedException class.
public MethodNotAllowedException(string message, Exception innerException = null)
Parameters
messagestringThe message that describes the HTTP status code.
innerExceptionExceptionThe exception that is the cause of the current exception.