.NET Web Api控制器在异常时返回Http 200状态代码

时间:2015-02-16 05:38:08

标签: jquery .net ajax asp.net-mvc asp.net-web-api

我正在使用JQuery客户端进行Ajax调用。

var ajaxCalls = [];
 ajaxCalls.push(executeOne());
 ajaxCalls.push(executeTwo());

function executeOne() {

            return $.ajax({
                type: "POST",
                async: true,
                url: URL,
                contentType: "application/json",
                data: JSON.stringify(Params),
                dataType: "json"
            });
        }
        ;

        function executeTwo() {

            return $.ajax({
                type: "POST",
                async: true,
                url: URL,
                contentType: "application/json",
                data: JSON.stringify(ParamsTwo),
                dataType: "json"
            });
        }
        ;




$.when.apply($, ajaxCalls).then(function () {
     //DO something

 }).fail(function () {
                //Do something 
        }).always(function () {

        });

在.net方面,我有一个简单的控制器,我抛出异常:

 [HttpPost]
    public HttpResponseMessage Results(ParamsModel data)
    {
        throw new Exception("Error");

    }

问题:状态代码返回200而不是500.因此,fail客户端块永远不会被执行。

请建议。

0 个答案:

没有答案