Table of Contents

MethodNotAllowedException Class

Definition

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

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.

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

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.

See Also