Gowri Pranith Kumar
Gowri Pranith Kumar

Reputation: 1685

Return 405 Method Not allowed from Asp.Net Core Webapi

In the below API controller , How to return 405 Method Not allowed if POST or PUT is called on the API. Currently it is returning 404 not found .

[HttpGet]        
        public ActionResult<IEnumerable<Customer>> Get()
        {
            string query = "select* from Customers;";
            try
            {
                List<Customer> collection = GetCustomers(query);
                return Ok(collection);
            }
            catch (System.Exception)
            {
                return BadRequest();
            }
        }

Upvotes: 4

Views: 11313

Answers (1)

ozanmut
ozanmut

Reputation: 3234

This issue is discussed in this thread: https://github.com/aspnet/Mvc/issues/388

Upvotes: 3

Related Questions