Asp.NET 操作方法成功但浏览器收到 500 jQuery.ajax
Asp.NET action method succeeds but browser receives a 500 with jQuery.ajax
我有一个页面发出 AJAX 请求以更新页面上的小定价部分。当 运行 在我的本地机器上时它工作正常,但是当发布到我们的开发服务器时, AJAX 调用收到内部服务器错误 500 响应。我迷路的部分是当我附加调试器并单步执行代码时,操作似乎成功完成所以似乎发生了一些事情 after 操作方法运行导致 500 但是我不知道在操作方法之后运行的任何代码。
这是 .js ajax、操作方法及其响应:
_paymentPlanXhr = $.ajax({
type: "POST",
url: $("#_Booking_UpdatePaymentUrl").val(),
data: "purchaseMem="+ purchaseMem +"&sid=" + selectedStudentID,
cache: false,
dataType: "json",
timeout: 120000,
success: function (response) {
...
},
error: function (jqXHR, textStatus, errorThrow) {
_paymentPlanXhr = null;
$loadingDiv.hide();
_pendingPaymentPlanUpdate = false;
//If this was really an error, not the result of our code cancelling the request
if (textStatus != "abort")
$("#divPaymentLoadError").show();
}
});
操作方法:
[HttpPost]
public ContentResult Booking_UpdatePayment(PsnBookingPage currentPage, bool purchaseMem, Guid sid)
{
AjaxResponse result = new AjaxResponse();
BookingViewModel bookingVM = new BookingViewModel();
try
{
//Code for building the vm omitted for brevity since it succeeds.
result.Content = this.RenderPartialView(_paymentViewUrl, viewModel, true);
}
catch (Exception ex)
{
viewModel.AbortView = true;
viewModel.AbortMessage = "We're sorry! Something went wrong and we were unable to load the view.";
}
return result.ToContentResult();
}
result.ToContentResult:
{"HasError":false,"ErrorMessage":null,"Content":" <div id=\"divSelectDate\"><div class=\"data-price\">Due Today: .00</div><div class=\"data-price\">Due on Event Date: [=14=].00</div></div>","Data":null}
我不知道这是否是一个因素,但这是一个基于 EPiServer 的站点。如何找到 500 的来源?
编辑:
也许这与 EPiServer 有关,因为即使我关闭了自定义错误,我使用 500 得到的响应有以下内容而不是黄色 asp.net 错误屏幕:
<html>
<head>
<meta name="robots" content="noindex,nofollow"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>
Page could not be loaded
</title>
<style type="text/css">
body{font-size:65%;color:black;background-color:White;}
form{font-size:1.2em;}
body,table{font-family:Verdana;font-weight:normal;}
h1{color: gray;font-size: 1.4em;font-family:Verdana;margin:0.5em 0 0 0;}
h2{font-size:1.2em;font-weight:bold;}
h3{display: inline;font-weight:bold;font-size: 1.0em;}
.ExceptionInfo{margin:0.6em 0 0.6em 0.2em;}
.StackTrace{font-family:"Lucida Console";}
th{font-size: 0.8em;text-align:left;white-space: nowrap;}
td{font-size: 0.7em;}
.DetailedHeader{font-weight:bold;border: 1px solid black;padding:4px;text-align:center;}
.ReportForm{font-family:Verdana;font-weight:normal;font-size: 1.0em;color:black;}
.SubmitButton{font-family:Verdana;font-weight:normal;font-size: 1.0em;color:black;}
</style>
<script type="text/javascript">
<!--
function onNavigate(newPageLink)
{
return -1;
}
function onCommand(newCommand)
{
return -1;
}
// -->
</script>
</head><body>
<h1 class="Title">
Page could not be loaded
</h1><p style="width:40em;">The link you specified does not work. This may either be the result of temporary maintenance or an incorrect link.
</p></body></html>
我认为这是一个 chrome 页面,但另一个线程建议它是 EPiServer 生成的页面。
您正在 web.config(或 episerver.config)的 episerver 部分的 applicationSettings 元素上查找 globalErrorHandling 属性。
如果您使用的是 EPiServer 7 或更早版本,它也可能在站点元素上。
我有一个页面发出 AJAX 请求以更新页面上的小定价部分。当 运行 在我的本地机器上时它工作正常,但是当发布到我们的开发服务器时, AJAX 调用收到内部服务器错误 500 响应。我迷路的部分是当我附加调试器并单步执行代码时,操作似乎成功完成所以似乎发生了一些事情 after 操作方法运行导致 500 但是我不知道在操作方法之后运行的任何代码。
这是 .js ajax、操作方法及其响应:
_paymentPlanXhr = $.ajax({
type: "POST",
url: $("#_Booking_UpdatePaymentUrl").val(),
data: "purchaseMem="+ purchaseMem +"&sid=" + selectedStudentID,
cache: false,
dataType: "json",
timeout: 120000,
success: function (response) {
...
},
error: function (jqXHR, textStatus, errorThrow) {
_paymentPlanXhr = null;
$loadingDiv.hide();
_pendingPaymentPlanUpdate = false;
//If this was really an error, not the result of our code cancelling the request
if (textStatus != "abort")
$("#divPaymentLoadError").show();
}
});
操作方法:
[HttpPost]
public ContentResult Booking_UpdatePayment(PsnBookingPage currentPage, bool purchaseMem, Guid sid)
{
AjaxResponse result = new AjaxResponse();
BookingViewModel bookingVM = new BookingViewModel();
try
{
//Code for building the vm omitted for brevity since it succeeds.
result.Content = this.RenderPartialView(_paymentViewUrl, viewModel, true);
}
catch (Exception ex)
{
viewModel.AbortView = true;
viewModel.AbortMessage = "We're sorry! Something went wrong and we were unable to load the view.";
}
return result.ToContentResult();
}
result.ToContentResult:
{"HasError":false,"ErrorMessage":null,"Content":" <div id=\"divSelectDate\"><div class=\"data-price\">Due Today: .00</div><div class=\"data-price\">Due on Event Date: [=14=].00</div></div>","Data":null}
我不知道这是否是一个因素,但这是一个基于 EPiServer 的站点。如何找到 500 的来源?
编辑:
也许这与 EPiServer 有关,因为即使我关闭了自定义错误,我使用 500 得到的响应有以下内容而不是黄色 asp.net 错误屏幕:
<html>
<head>
<meta name="robots" content="noindex,nofollow"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>
Page could not be loaded
</title>
<style type="text/css">
body{font-size:65%;color:black;background-color:White;}
form{font-size:1.2em;}
body,table{font-family:Verdana;font-weight:normal;}
h1{color: gray;font-size: 1.4em;font-family:Verdana;margin:0.5em 0 0 0;}
h2{font-size:1.2em;font-weight:bold;}
h3{display: inline;font-weight:bold;font-size: 1.0em;}
.ExceptionInfo{margin:0.6em 0 0.6em 0.2em;}
.StackTrace{font-family:"Lucida Console";}
th{font-size: 0.8em;text-align:left;white-space: nowrap;}
td{font-size: 0.7em;}
.DetailedHeader{font-weight:bold;border: 1px solid black;padding:4px;text-align:center;}
.ReportForm{font-family:Verdana;font-weight:normal;font-size: 1.0em;color:black;}
.SubmitButton{font-family:Verdana;font-weight:normal;font-size: 1.0em;color:black;}
</style>
<script type="text/javascript">
<!--
function onNavigate(newPageLink)
{
return -1;
}
function onCommand(newCommand)
{
return -1;
}
// -->
</script>
</head><body>
<h1 class="Title">
Page could not be loaded
</h1><p style="width:40em;">The link you specified does not work. This may either be the result of temporary maintenance or an incorrect link.
</p></body></html>
我认为这是一个 chrome 页面,但另一个线程建议它是 EPiServer 生成的页面。
您正在 web.config(或 episerver.config)的 episerver 部分的 applicationSettings 元素上查找 globalErrorHandling 属性。
如果您使用的是 EPiServer 7 或更早版本,它也可能在站点元素上。