MethodNotAllowedException Class
Definition
- Namespace
- Cuemon.AspNetCore.Http
- Assemblies
- 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
| Name | Description |
|---|---|
| MethodNotAllowedException() | Initializes a new instance of the MethodNotAllowedException class. |
| MethodNotAllowedException(Exception) | Initializes a new instance of the MethodNotAllowedException class. |
| MethodNotAllowedException(string, Exception) | Initializes a new instance of the MethodNotAllowedException class. |