簡體   English   中英

WebApi HttpPost在Windows Azure上不起作用

[英]WebApi HttpPost not working on Windows Azure

我正在使用將WebApi2與帶有Angular和D3 api的MVC一起使用的示例項目。 我的WebApi遇到問題。 在具有Azure數據庫連接字符串的本地計算機上一切正常,但是當我在Azure上發布相同字符串時,我的HttpPost停止工作,而HttpGet工作正常。

[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

我可以將帖子發送到您的網址:

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

它似乎不是跨域問題,但只是為了確保您是否在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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM