'Issue after deploying ASP.NET Web API to production
I tested ASP.NET Web API in local environment with IIS Express and on other server with full IIS. At both places, token api and post api is working fine. I am using System.Web.Http namespace as suggested. However, after deploying it to shared hosting server, I am getting below error:
Token API:
"error": "unsupported_grant_type"
Post API (method with [HttpPost] of System.Web.Http):
"Message": "The requested resource does not support http method 'GET'."
Post API code:
[AllowAnonymous]
[HttpPost]
[Route("api/test")]
public IHttpActionResult Test([FromBody] Employee emp)
{
...
}
I am using default Routing available in WebApiConfig.cs as shown below. Not sure whether it matters as I am already decorating API method with Route:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
I tried deploying with FileSystem method (Upload files to server and configure application in IIS) and Web Deploy method to directly deploy API to server. I am using Postman to test and using the same Http Method (Post) and body that I use while testing it locally.
What could be difference between local IIS Express/IIS and shared hosting server IIS that causes this issue?
Solution 1:[1]
The issue was that the hosting provider had secondary URL which needs to be used instead of public URL. I replaced public URL with secondary URL in my API call and it started working.
Solution 2:[2]
As far as I know, the "error": "unsupported_grant_type"
means you used the wrong parameter in your request, I suggest you could re-check your request header or body to make sure you have used the right parameter type.
The "Message": "The requested resource does not support http method 'GET'."
error means you used the get method instead of post to send the request.
If you use the post really, I suggest you could use Fail request tracing to see what has happened when you use the postman to send the request. Article.
`
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Ramesh |
Solution 2 | Brando Zhang |