2014-03-06 70 views
2

我正在使用帶有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

回答

0

它不會出現是一個跨領域的問題,但只是爲了確保,你允許它在你的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

1

我可以發個帖子的網址:

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