ASP.NET WebApi : (405) Method Not Allowed

I found the solution.

I checked the request by Fiddler.When I send a POST request to API it automatically redirect to the same address with this new parameter AspxAutoDetectCookieSupport=1

How to remove AspxAutoDetectCookieSupport=1

Finally I changed the cookieless="AutoDetect" in web.config to cookieless="UseCookies" and the problem solved.


I know this is an old post, but maybe this might help someone else. I just had a similar issue, getting a 405 error "Get not allowed" when I was clearly doing a post in postman. Turned out, I was submitting to the URL using http instead of https. Changing to https fixed it.


     byte[] postData = Encoding.UTF8.GetBytes(postParameters);
            myReq.ContentLength = postData.Length;
            myReq.ContentType = "application/x-www-form-urlencoded";
            using (Stream requestWrite = myReq.GetRequestStream())
            {
                requestWrite.Write(postData, 0, postData.Length);

You're most likely not sending a proper x-www-form-urlencoded request. You're likely not encoding the data properly from whatever is passed in as postParameters. See Post form data using HttpWebRequest

Since you're not generating a valid OrderResult object according to x-www-form-urlencoded, the route selector does not select your Buy action. This is why you get POST is not allowed.

You would likely get to the controller if you changed OrderResult value = null as it is now an optional parameter. However this isn't what you want, unless you're going to have a weird controller that behaves like:

Buy(OrderResult value = null)
{
    if(value== null)
        value = MyCustomDeserializeFromRequestBody(RequestContext)

    ...
}

Ultimately you just really shouldn't use this class there are much better constructs for modern development https://stackoverflow.com/a/31147762/37055 https://github.com/hhariri/EasyHttp off the top of my head