I have a single form which, depending on various underlying metadata will display different variations of a form. In a single case, only in the deployed application (works fine in dev and qa environments), one variant of the form causes a 500 Internal Server Error. I've examined the data sent back to the server in both the dev and live environments, and there's no difference at all.
The question is, how can I track down this 500 error? I have elmah installed, and its not getting tripped. I've set a Logging statement as the first action in my POST handler, and it never executes. I've set <customErrors mode="Off"/> in my web.config, and it doesn't show me a better error message. The only thing I can think of is that I have some kind of routing issue, but that doesn't really feel right since the same data works just fine to route for other servers.
So, what else can I do to track down this elusive bug?
I have a reporting module in the app that I'm building, and it is metadata driven. Once they select which report they wish to execute, the software pulls up the metadata for the report, figures out what parameters need to be collected, and displays a form to gather them from the user. Once the user has filled out the form, they click a button, which submits the form via a jquery $.ajax() call. The controller should pick up the incoming form post, validate the form data, and then either re-display the form or return a json with a url to present the report renderer action.
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 }
);
}
}
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);
}
});
In this case, the answer was to run the app on the live webserver.
Once I'd done that, I was able to see more details about the error. I had expected that setting <customErrors mode="Off"/> in the web.config would accomplish the same thing, but evidently, I was wrong about that.
Anyhow, after running a browser from the webserver itself, I was able to see that the error was A potentially dangerous Request.Form value was detected from the client (repModel.sQuery="...ND THEDATE<DATEADD(dd,1,@dtEnd...")., and thats enough info for me to figure out where to go next.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With