WebApi HttpPost不能在Windows Azure上工作

问题描述:

我正在使用带有Angular和D3 api的MVC的WebApi2的示例项目。我面临WebApi的一个问题。一切工作正常与本地机器Azure数据库连接字符串,但当我发布相同的Azure我的HttpPost停止工作,而HttpGet工作正常。我现在面临的WebApi HttpPost不能在Windows Azure上工作

[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; 
} 

错误发表

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 
+1

看起来不是特定于azure的问题,请给出更多详细信息。 – ssilas777

+0

像什么细节?这是该网站的网址[http://sampledataweb.azurewebsites.net/](http://sampledataweb.azurewebsites.net/) – RaviMittal

它不会出现是一个跨领域的问题,但只是为了确保,你允许它在你的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> 
+0

还是没有相同的回应。 POST http://sampledataweb.azurewebsites.net/api/dashboard/addnewassignment 500(内部服务器错误) – RaviMittal

我可以发个帖子的网址:

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 

所以这个问题是在你的CoursePersonAssignmentModel或AssignmentService.AddAssignment方法。安装一个nuget记录(即Elmah),它会帮助你发现错误。另一个不错的选择是,您可以使用intellitrace进行调试:http://blogs.msdn.com/b/zainnab/archive/2013/02/12/understanding-intellitrace-part-i-what-the-is-intellitrace.aspx