C# WebApi HttpPost在Windows Azure上不工作
我正在使用WebApi2和MVC以及Angular和D3API进行一个示例项目。我的WebApi面临一个问题。使用Azure数据库连接字符串在本地计算机上一切正常,但当我在Azure上发布相同的字符串时,我的HttpPost停止工作,而HttpGet正常工作C# WebApi HttpPost在Windows Azure上不工作,c#,azure,asp.net-web-api,C#,Azure,Asp.net Web Api,我正在使用WebApi2和MVC以及Angular和D3API进行一个示例项目。我的WebApi面临一个问题。使用Azure数据库连接字符串在本地计算机上一切正常,但当我在Azure上发布相同的字符串时,我的HttpPost停止工作,而HttpGet正常工作 [HttpPost] [Route("api/dashboard/addnewassignment")] public WebApiD3Sample.ViewModels.CoursePersonAssignmentModel AddNew
[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
这似乎不是一个跨域问题,但只是为了确保,您是否允许在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>
我可以向您的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
因此,问题出在CoursePersonAssignmentModel或AssignmentService.AddAssignment方法中。安装一个nuget to log(即Elmah),它将帮助您捕获错误。另一个很好的选择是,您可以使用intellitrace进行调试:看起来不像是azure特有的问题,请提供更多详细信息。详细信息如什么??这是网站url没有仍然相同的响应。POST 500(内部服务器错误)