从ajax调用调试c# web方法



我有一个asp.net (web forms) c#代码后面的页面,有一个web方法,我从一个ajax调用在同一页面上调用。

ajax POST调用后,我得到一个通用的"内部服务器错误已经发生"。

我想通过web方法代码来确定发生了什么。

我该怎么做?不命中断点。是否有我必须依附的流程?我找不到任何关于什么进程将在我的本地IIS上运行处理WebMethod调用的信息?

注意:我可以调试和步进正常的事件响应函数,如Page_Load和其他。

ajax代码:

 $.ajax({
    type: "POST",
    url: "/Patrol/Report.aspx/GetSPResults",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    data: JSON.stringify(postData)
}).done(function (result) {
    var results = "";
    if (result.d.length > 0) {
        results = JSON.parse(result.d);
    }
    buildViewModel(results);
    kendo.bind($("#Report"), viewModel);
    $("Checkpoints").fadeIn(100);
}).fail(function (jqXHR, textStatus, err) {
    alert("An error has occurred: " + err);
});
web方法:

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static string GetSPResults(string reportId, string sproc, Dictionary<string, string> parameters, string[] ensureArrays)
{
    Int32 intReportId;
    Console.WriteLine("Report.aspx/GetSPResults called");
    if (Int32.TryParse(reportId, out intReportId))
    {
        AV.Data.SqlSPHelper avdata = new AV.Data.SqlSPHelper(ConfigurationManager.ConnectionStrings["ProductionConnectionString"].ConnectionString);
        Dictionary<string, string> sprocCheckParams = new Dictionary<string, string>()
        {
            {"Sproc", sproc},
            {"ReportID", reportId}
        };
        XElement sprocCheck = avdata.ExecuteSPXmlXElement("[dw].[spReport_Sproc_Check]", sprocCheckParams, null);
        if (sprocCheck.GetAttributeVal("result") == "1")
        {
            XElement result = avdata.ExecuteSPXmlXElement(sproc, parameters, null);
            result = result?.RemoveAllNamespacesAndNils();
            if (result != null)
            {
                var jsonResults = JsonConvertWrapper.SerializeXelement(result, ensureArrays, true, Formatting.Indented, true);
                return jsonResults;
            }
        }
    }
    return string.Empty;
}

问题是我的post请求的参数名称与WebMethod函数签名中的参数名称不匹配。

POST请求有参数名称reportID时,WebMethod期望reportId

最新更新