Reputation: 69
I have a web api application that I have written and tested locally using VS2017 and IIS Express 10. I am able to POST and GET when running locally using either HTTP or HTTPS. When I publish to Azure I am getting method not allowed on both the post and get over HTTP.
How do I configure the Azure server to allow all the HTTP verbs?
How to configure HTTPS on Azure is another story...
Thanks :-)
Upvotes: 5
Views: 18319
Reputation: 1671
I had a similar experience, and the problem was that the Azure Web App was configured to "HTTPS Only". As the client was sending HTTP, I disabled this option and it worked:
Upvotes: 0
Reputation: 1553
Try it
var result = new ObjectResult("YOUR MESSAGE");
result.StatusCode = StatusCodes.Status405MethodNotAllowed;
return result;
you need to add this => namespace Microsoft.AspNetCore.Mvc
Upvotes: -1
Reputation: 819
I had a similar issue and the solution here worked. Simply change the http to https in the POST call and test the result. For example in postman, only change the http to https.
Azure App Service Error 405 - The request could not be completed. (Method Not Allowed)
Upvotes: 9
Reputation: 71
Please check if you are passing the params correctly. Wasted a lot of time figuring that out.
Upvotes: 1
Reputation: 18387
I'm assuming that your web application uses a js library/framework (react / angular). Usually before the request, they send a preflight CORS request using the "Options" verb. I believe that it's the one that it's being blocked.
One easy way to solve this:
Web.config:
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="GET, PUT, POST, DELETE, HEAD" />
<add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept" />
</customHeaders>
</httpProtocol>
</system.webServer>
BaseApiController.cs:
public class BaseApiController : ApiController
{
public HttpResponseMessage Options()
{
return new HttpResponseMessage { StatusCode = HttpStatusCode.OK };
}
}
If it's a cross-domain problem, you can configure CORS directly through Azure portal:
https://learn.microsoft.com/en-us/azure/app-service-api/app-service-api-cors-consume-javascript
Upvotes: 0