I have a web Api Controller and I tested all the actions on localhost and it works well. But when I posted it on a web server, Just Actions c [HttpGet]works and [HttpPost]Actions return an Http 405 error
public class ContentController : ApiController
{
[HttpGet]
public async Task<IHttpActionResult> AdvantageList()
{
}
[HttpPost]
public async Task<IHttpActionResult> SaveAdvantage(ContentModel model)
{
}
}
I used below method on client
var r = await ClientManager.Client.PostAsJsonAsync("api/Content/SaveAdvantage", Advantage);
But it will be retrieved below the response server. I used the method PostAsJsonAsync, but it says The requested resource does not support http method 'GET'
Does anyone know why?
{ StatusCode: 405, ReasonPhrase: " ", : 1.0, : System.Net.Http.StreamContent, : { Pragma: no-cache X-Powered-By-Plesk: PleskWin : Cache-Control: no-cache : , 29 2017 08:53:51 GMT : Microsoft-IIS/8.0 X-AspNet-: 4.0.30319 X-Powered-By: ASP.NET -: 72 : POST Content-Type: application/json; = UTF-8 : -1 }}
"{\" message\ ": \" http 'GET'.\ "}"
- api:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{action}");
config.Routes.MapHttpRoute("WithId", "api/{controller}/{action}/{id}", new { id = RouteParameter.Optional });
config.Routes.MapHttpRoute("TwoId", "api/{controller}/{action}/{id}/{id2}", new { id = RouteParameter.Optional, id2 = RouteParameter.Optional });
config.MapHttpAttributeRoutes();
var formatter = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
formatter.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver();
}
}
Web.config
<system.webServer>
<handlers>
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<remove name="OPTIONSVerbHandler" />
<remove name="TRACEVerbHandler" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
webapi2 winform.