简体   繁体   中英

WebApi HttpPost not working on Windows Azure

I am working on a sample project using WebApi2 with MVC with Angular and D3 api. I am facing an issue with my WebApi. Everything working fine on local machine with Azure database connection string but when i publish the same on Azure my HttpPost stops working while HttpGet is working fine.

[HttpPost]
[Route("api/dashboard/addnewassignment")]
public WebApiD3Sample.ViewModels.CoursePersonAssignmentModel AddNewCoursePersonAssignment([FromBody]WebApiD3Sample.ViewModels.CoursePersonAssignmentModel model) 
{
     if (ModelState.IsValid) {
          var modelAfterSave = AssignmentService.AddAssignment(model);
          return modelAfterSave;
     }
     ModelState.AddModelError("Invalid", "Not a Valid Save");
     return model;
}

Error that i am facing on published

Failed to load resource: the server responded with a status of 500 (Internal Server Error) 
http://sampledataweb.azurewebsites.net/api/dashboard/addnewassignment
    Object
    message: "An error has occurred."
__proto__: Object

I could send a post to your URL:

Status Code: 200 OK
Access-Control-Allow-Headers: Origin,X-Requested-With,Content-Type,Accept
Access-Control-Allow-Origin: *
Cache-Control: no-cache
Content-Encoding: gzip
Content-Length: 123
Content-Type: application/json; charset=utf-8
Date: Thu, 06 Mar 2014 18:48:25 GMT
Expires: -1
Pragma: no-cache
Server: Microsoft-IIS/8.0
Set-Cookie: ARRAffinity=dbb5756ce35e0494cf70c90b9aba80f70f92f607fb3ebb3e7dffe4ecc1aba24a;Path=/;Domain=sampledataweb.azurewebsites.net WAWebSiteSID=696c72c37b2e472b90f6033923558edd; Path=/; HttpOnly
Vary: Accept-Encoding
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET

so the problem is in your CoursePersonAssignmentModel or AssignmentService.AddAssignment method. Install a nuget to log (ie Elmah) and it will help you to catch the error. Another great option, you can debug using intellitrace: http://blogs.msdn.com/b/zainnab/archive/2013/02/12/understanding-intellitrace-part-i-what-the-is-intellitrace.aspx

It doesn't appear to be a cross domain issue, but just to make sure, did you allow it in your web.config?

<system.webServer>
    <httpProtocol>
        <customHeaders>
            <remove name="Access-Control-Allow-Origin" />
            <remove name="Access-Control-Allow-Headers" />
            <add name="Access-Control-Allow-Origin" value="*" />
            <add name="Access-Control-Allow-Headers" value="Origin,X-Requested-With,Content-Type,Accept" />
        </customHeaders>
    </httpProtocol>
</system.webServer>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM