即使 OnResultExecuted 成功调用后,JsonResult 也未返回
我有一个“无会话”控制器,其操作返回 JsonResult。我的客户端 Javascript 使用 Jquery ajax 通过 HTTP GET 调用此操作
[HttpGet]
public JsonResult Index()
{
....
// myResult has three properties of type bool, int and a string
var jsonResult = Json(myResult, "application/json", JsonRequestBehavior.AllowGet);
return jsonResult;
}
此代码被执行,并且我已经验证了 OnResultExecuted
被调用,没有任何异常。
客户端 JS
xhrNotification = $.ajax({
url: '/MyController/', // default action
type: 'get',
dataType: 'json',
cache: false,
async: true,
success: function (n, timeout, message) {
},
error: function (data) {
}
});
但 jsonResult 只是偶尔到达客户端。我一直在使用 Fiddler 观察请求/响应。即使执行了我的操作,HTTP 请求也没有响应。我正在 Visual Studio 2010 下开发此程序。
感谢任何帮助。
编辑:在进一步调试时,我发现执行我的操作后引发异常
System.Net.Sockets.SocketException occurred
Message=An established connection was aborted by the software in your host machine
Source=System
ErrorCode=10053
NativeErrorCode=10053
StackTrace:
at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
部分堆栈跟踪如下
System.dll!System.Net.Sockets.Socket.Send(byte[] buffer, int offset, int size, System.Net.Sockets.SocketFlags socketFlags) + 0x5a bytes
WebDev.WebHost40.dll!Microsoft.VisualStudio.WebHost.Connection.WriteBody(byte[] data, int offset, int length) + 0x40 bytes
[Appdomain Transition]
> WebDev.WebHost40.dll!Microsoft.VisualStudio.WebHost.Request.FlushResponse(bool finalFlush) + 0x128 bytes
System.Web.dll!System.Web.HttpResponse.Flush(bool finalFlush) + 0x4cb bytes
System.Web.dll!System.Web.HttpRuntime.FinishRequest(System.Web.HttpWorkerRequest wr, System.Web.HttpContext context, System.Exception e) + 0x80 bytes
System.Web.dll!System.Web.HttpRuntime.OnHandlerCompletion(System.IAsyncResult ar) + 0xa6 bytes
System.Web.dll!System.Web.HttpAsyncResult.Complete(bool synchronous, object result, System.Exception error, System.Web.RequestNotificationStatus status) + 0x3e bytes
System.Web.dll!System.Web.HttpApplication.ApplicationStepManager.ResumeSteps(System.Exception error) + 0x25e bytes
System.Web.dll!System.Web.HttpApplication.ResumeStepsFromThreadPoolThread(System.Exception error) + 0x28 bytes
System.Web.dll!System.Web.HttpApplication.CallHandlerExecutionStep.OnAsyncHandlerCompletion(System.IAsyncResult ar) + 0x183 bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncUtil.WrapCallbackForSynchronizedExecution.AnonymousMethod__1() + 0x14 bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.SynchronizationContextUtil.Sync.AnonymousMethod__3() + 0x16 bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.SynchronizationContextUtil.Sync<System.Web.Mvc.Async.AsyncVoid>.AnonymousMethod__0(object o) + 0x32 bytes
System.Web.dll!System.Web.AspNetSynchronizationContext.CallCallbackPossiblyUnderLock(System.Threading.SendOrPostCallback callback, object state) + 0x4a bytes
System.Web.dll!System.Web.AspNetSynchronizationContext.CallCallback(System.Threading.SendOrPostCallback callback, object state) + 0x5f bytes
System.Web.dll!System.Web.AspNetSynchronizationContext.Send(System.Threading.SendOrPostCallback callback, object state) + 0x9 bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.SynchronizationContextUtil.Sync<System.Web.Mvc.Async.AsyncVoid>(System.Threading.SynchronizationContext syncContext, System.Func<System.Web.Mvc.Async.AsyncVoid> func) + 0x58 bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.SynchronizationContextUtil.Sync(System.Threading.SynchronizationContext syncContext, System.Action action) + 0x46 bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncUtil.WrapCallbackForSynchronizedExecution.AnonymousMethod__0(System.IAsyncResult asyncResult) + 0x6f bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult<System.Web.Mvc.Async.AsyncVoid>.ExecuteAsynchronousCallback(bool timedOut) + 0x37 bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult<System.Web.Mvc.Async.AsyncVoid>.HandleAsynchronousCompletion(System.IAsyncResult asyncResult) + 0x1e bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult<System.Web.Mvc.Async.AsyncVoid>.ExecuteAsynchronousCallback(bool timedOut) + 0x37 bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult<System.Web.Mvc.Async.AsyncVoid>.HandleAsynchronousCompletion(System.IAsyncResult asyncResult) + 0x1e bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult<System.Web.Mvc.Async.AsyncVoid>.ExecuteAsynchronousCallback(bool timedOut) + 0x37 bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult<System.Web.Mvc.Async.AsyncVoid>.HandleAsynchronousCompletion(System.IAsyncResult asyncResult) + 0x1e bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult<bool>.ExecuteAsynchronousCallback(bool timedOut) + 0x37 bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult<bool>.HandleAsynchronousCompletion(System.IAsyncResult asyncResult) + 0x1e bytes
I have a 'Session-Less' Controller with an action that returns JsonResult. My client side Javascript uses Jquery ajax to call this action via HTTP GET
[HttpGet]
public JsonResult Index()
{
....
// myResult has three properties of type bool, int and a string
var jsonResult = Json(myResult, "application/json", JsonRequestBehavior.AllowGet);
return jsonResult;
}
This code gets executed and I have verified that OnResultExecuted
is called without any exception.
Client side JS
xhrNotification = $.ajax({
url: '/MyController/', // default action
type: 'get',
dataType: 'json',
cache: false,
async: true,
success: function (n, timeout, message) {
},
error: function (data) {
}
});
But the jsonResult only occasionally gets to the client side. I have been observing the request/response using Fiddler. The HTTP request has no response even after my action is executed. I am developing this under Visual Studio 2010.
Any help is appreciated.
EDIT: On further debugging I found an exception is raised after my Action is executed
System.Net.Sockets.SocketException occurred
Message=An established connection was aborted by the software in your host machine
Source=System
ErrorCode=10053
NativeErrorCode=10053
StackTrace:
at System.Net.Sockets.Socket.Send(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
Partial stack trace is as below
System.dll!System.Net.Sockets.Socket.Send(byte[] buffer, int offset, int size, System.Net.Sockets.SocketFlags socketFlags) + 0x5a bytes
WebDev.WebHost40.dll!Microsoft.VisualStudio.WebHost.Connection.WriteBody(byte[] data, int offset, int length) + 0x40 bytes
[Appdomain Transition]
> WebDev.WebHost40.dll!Microsoft.VisualStudio.WebHost.Request.FlushResponse(bool finalFlush) + 0x128 bytes
System.Web.dll!System.Web.HttpResponse.Flush(bool finalFlush) + 0x4cb bytes
System.Web.dll!System.Web.HttpRuntime.FinishRequest(System.Web.HttpWorkerRequest wr, System.Web.HttpContext context, System.Exception e) + 0x80 bytes
System.Web.dll!System.Web.HttpRuntime.OnHandlerCompletion(System.IAsyncResult ar) + 0xa6 bytes
System.Web.dll!System.Web.HttpAsyncResult.Complete(bool synchronous, object result, System.Exception error, System.Web.RequestNotificationStatus status) + 0x3e bytes
System.Web.dll!System.Web.HttpApplication.ApplicationStepManager.ResumeSteps(System.Exception error) + 0x25e bytes
System.Web.dll!System.Web.HttpApplication.ResumeStepsFromThreadPoolThread(System.Exception error) + 0x28 bytes
System.Web.dll!System.Web.HttpApplication.CallHandlerExecutionStep.OnAsyncHandlerCompletion(System.IAsyncResult ar) + 0x183 bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncUtil.WrapCallbackForSynchronizedExecution.AnonymousMethod__1() + 0x14 bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.SynchronizationContextUtil.Sync.AnonymousMethod__3() + 0x16 bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.SynchronizationContextUtil.Sync<System.Web.Mvc.Async.AsyncVoid>.AnonymousMethod__0(object o) + 0x32 bytes
System.Web.dll!System.Web.AspNetSynchronizationContext.CallCallbackPossiblyUnderLock(System.Threading.SendOrPostCallback callback, object state) + 0x4a bytes
System.Web.dll!System.Web.AspNetSynchronizationContext.CallCallback(System.Threading.SendOrPostCallback callback, object state) + 0x5f bytes
System.Web.dll!System.Web.AspNetSynchronizationContext.Send(System.Threading.SendOrPostCallback callback, object state) + 0x9 bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.SynchronizationContextUtil.Sync<System.Web.Mvc.Async.AsyncVoid>(System.Threading.SynchronizationContext syncContext, System.Func<System.Web.Mvc.Async.AsyncVoid> func) + 0x58 bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.SynchronizationContextUtil.Sync(System.Threading.SynchronizationContext syncContext, System.Action action) + 0x46 bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncUtil.WrapCallbackForSynchronizedExecution.AnonymousMethod__0(System.IAsyncResult asyncResult) + 0x6f bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult<System.Web.Mvc.Async.AsyncVoid>.ExecuteAsynchronousCallback(bool timedOut) + 0x37 bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult<System.Web.Mvc.Async.AsyncVoid>.HandleAsynchronousCompletion(System.IAsyncResult asyncResult) + 0x1e bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult<System.Web.Mvc.Async.AsyncVoid>.ExecuteAsynchronousCallback(bool timedOut) + 0x37 bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult<System.Web.Mvc.Async.AsyncVoid>.HandleAsynchronousCompletion(System.IAsyncResult asyncResult) + 0x1e bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult<System.Web.Mvc.Async.AsyncVoid>.ExecuteAsynchronousCallback(bool timedOut) + 0x37 bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult<System.Web.Mvc.Async.AsyncVoid>.HandleAsynchronousCompletion(System.IAsyncResult asyncResult) + 0x1e bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult<bool>.ExecuteAsynchronousCallback(bool timedOut) + 0x37 bytes
System.Web.Mvc.dll!System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult<bool>.HandleAsynchronousCompletion(System.IAsyncResult asyncResult) + 0x1e bytes
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用此调用,看看会发生什么:(可能需要确保将类型设置为“GET”,而不是“get”)
此外,您可能只想在控制器中执行此操作:
Try using this call and see what happens: (might want to make sure you set type to 'GET', not 'get')
Also, you may just want to do this in your controller: