Ajax Form Post产生500内部服务器错误

时间:2013-04-29 13:39:55

标签: asp.net-mvc

主要问题

我有一个表单,根据各种底层元数据,它将显示表单的不同变体。在单个案例中,仅在已部署的应用程序中(在dev和qa环境中正常工作),表单的一个变体会导致500内部服务器错误。我已经检查了在开发环境和实时环境中发送回服务器的数据,并没有任何区别。

问题是,如何追踪这500错误?我安装了elmah,它没有被绊倒。我已将Logging语句设置为POST处理程序中的第一个操作,并且它永远不会执行。我在我的web.config中设置了<customErrors mode="Off"/>,它没有向我显示更好的错误消息。我唯一能想到的是我遇到了某种路由问题,但这并不是很正确,因为相同的数据可以很好地路由到其他服务器。

那么,我还能做些什么来追踪这个难以捉摸的错误?

背景资料

我正在构建的应用中有一个报告模块,它是元数据驱动的。一旦他们选择了他们希望执行的报告,软件就会提取报告的元数据,找出需要收集的参数,并显示一个表单以便从用户那里收集它们。一旦用户填写了表单,他们就会单击一个按钮,该按钮通过jquery $ .ajax()调用提交表单。控制器应该获取传入的表单帖子,验证表单数据,然后重新显示表单或返回带有URL的json以显示报表呈现器操作。

路线配置

public class RouteConfig {
    public static void RegisterRoutes(RouteCollection routes) {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");


        routes.MapRoute(
             name: "Default",
             url: "{controller}/{action}/{id}",
             defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );


    }
}

Ajax邮政编码

var ajaxUrl = this.action;
var ajaxType = this.method;
var ajaxData = $(this).serialize();
$.ajax({
    url: ajaxUrl,
    type: ajaxType,
    data: ajaxData,
    success:
        function(result) {
            // did we get a JSON back from the server?
            if (typeof(result) === "object") { //deal with the return result...   
                if (window.console) console.log("-- reportParam form submit passed validation");
                $("#popupDialog").popup("close");
                //need non-ajax version to go to url so we get a dom refresh - we want a new page also
                // window.location.href =
                window.open(result.URL, '_blank');
            } else {
                if (window.console) console.log("-- reportParam form failed validation");
                $('#popupDialog').html(result);
                $('#popupDialog').trigger('create');
                var _RPT = RevTrak.Portal.Report;
                _RPT.Index.initBindings();
            }
        },

    complete: function() {

        if (window.console) console.log("-- paramEdit form submit ajax call complete"); //this indicates we passed validation
    },
    error: function(xhr, textStatus, errorThrown) {
        var sErrMsg = "";
        sErrMsg += "paramEdit form submit error ";
        sErrMsg += "\n\n" + " - textStatus :" + textStatus;
        sErrMsg += "\n\n" + " - Error Status :" + xhr.status;
        sErrMsg += "\n\n" + " - Error type :" + errorThrown;
        sErrMsg += "\n\n" + " - Error message :" + xhr.responseText;

        if (window.console) console.log(sErrMsg)
        alert(sErrMsg);
    }
});

谢谢!

1 个答案:

答案 0 :(得分:2)

在这种情况下,答案是在实时网络服务器上运行该应用。

一旦我这样做了,我就能看到有关错误的更多细节。我原本以为在web.config中设置<customErrors mode="Off"/>会完成同样的事情,但显然我错了。

无论如何,在从网络服务器本身运行浏览器之后,我能够看到错误是A potentially dangerous Request.Form value was detected from the client (repModel.sQuery=&quot;...ND THEDATE&lt;DATEADD(dd,1,@dtEnd...&quot;).,这足以让我知道下一步该去哪里。

相关问题