500状态失败 - 角度js

时间:2015-01-14 16:33:58

标签: angularjs iis-6 asp.net-web-api

我使用角度js和web api进行投影。我的项目在IIS6.2中托管。基于一些链接,我已经将mime类型json添加到IIS。

当我试图在异常时抛出错误时,它的工作正常。但是当我成功返回响应对象时,它返回500状态。

实际上,在我托管之后,它在本地而不是IIS中工作正常。

我试过了,

  • 没有接受动词
  • 的[AcceptVerbs( “POST”)]
  • 的[AcceptVerbs( “后”, “GET”)]

当我从本地执行我的项目时,它执行完美而没有任何错误。 但是当我从服务器执行时,我得到了,

 Failed with 500 status

在这里我感到困惑,因为数据保存完好。但是500状态的错误失败了。

从web api,我得到了以下问题,如

<Error>
<Message>
The requested resource does not support http method 'GET'.
</Message>
</Error>

代码: Web Api

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

您能否提供解决方案来解决这个问题?

2 个答案:

答案 0 :(得分:0)

虽然这可能无法解决问题,但您似乎错过了这个地点。来自回复的标题。我不确定您的设置,但浏览器通常会在新资源的位置提供。

我认为您需要设置的属性是response.Headers.Location

答案 1 :(得分:0)

您是否尝试过使用卷发或邮递员。在使用角度测试之前,请先尝试使用Postman角度测试它。

数据:用户用户对象属性必须与 RegisterModel 中的属性匹配,否则.NET无法解析json并将其转换为类通过错误。