【发布时间】:2015-01-14 16:33:58
【问题描述】:
我有 Angular js 和 web api 的项目。我的项目托管在 IIS6.2 中。根据一些链接,我已将 mime 类型 json 添加到 IIS。
当我试图在异常上抛出错误时,它工作得很好。但是当我成功返回响应对象时,它返回 500 状态。
实际上,在我托管后它在本地而不是在 IIS 中运行良好。
我试过了,
- 不带accept动词
- [AcceptVerbs("Post")]
- [AcceptVerbs("Post","Get")]
当我从本地执行我的项目时,它执行完美,没有任何错误。 但是当我从服务器执行时,我得到了,
Failed with 500 status
在这里我很困惑,因为数据保存得很好。但是出现错误失败,状态为 500。
从 web api,我得到了以下问题,
<Error>
<Message>
The requested resource does not support http method 'GET'.
</Message>
</Error>
代码: 网络接口
[AcceptVerbs("Post")]
public HttpResponseMessage Signup(RegisterModel registerModel)
{
HttpResponseMessage response;
try
{
BLUser.UpdateUser(User);
response = Request.CreateResponse(HttpStatusCode.OK) or Request.CreateResponse(HttpStatusCode.Created);
}
catch (Exception ex)
{
HttpResponseMessage response = new HttpResponseMessage();
response.Content = new StringContent(errorMessage);
response.ReasonPhrase = errorMessage;
response.StatusCode = HttpStatusCode.BadRequest;
throw new HttpResponseException(response);
}
return response;
}
Angular js
$http({
method: "post",
url: "/api/Common/Signup",
data: user
});
你能提供解决这个问题的方法吗?
【问题讨论】:
-
您正在返回异常
return new HttpResponseException(response);,但您期望 200 OK 状态? -
抱歉误提。我没有回来,我只是抛出异常。我已经编辑了这个问题。请再看看我的问题。对不起。抛出新的 HttpResponseException(response);
-
您的问题与 AngularJS 无关,而 HTTP 错误 500 是内部服务器错误。
-
这是@Sapher 所说的后端错误。但是,如果您使用的是 Chrome,这可能会对您有所帮助,请转到开发人员工具栏,然后单击网络选项卡以查看该错误可能是什么。您可以尝试使用不同的数据进行多次调查。
-
但是在本地,我没有收到这个错误。这就是为什么困惑..
标签: angularjs iis-6 asp.net-web-api