我下载了样本SignalR进度条解决方案。它模拟服务器上长时间运行的进程,使用SignalR不断更新客户端。它在IISExpress上运行得很好,直到我在控制器中向我的方法添加了一个File.Copy(source, destination, true)
(参见下面)。
public JsonResult LongRunningProcess()
{
string directory = Server.MapPath("~/bin/") + @"\";
string source = directory + @"Templates\Template.xlsx";
string destination = directory + @"Spreadsheets\output file.xlsx";
System.IO.File.Copy(source, destination, true);
for (int i = 0; i <= 50; i++)
{
Thread.Sleep(500);
Functions.SendProgress("Process in progress...", i , 50);
}
return Json("", JsonRequestBehavior.AllowGet);
}
现在,我在服务器端接收到一个WebSocketException:
SignalR.Transports.WebSocketTransport Error: 0 : OnError(7bdc2904-8f12-4324-898f-58e4a9f4e686, System.Net.WebSockets.WebSocketException (0x800703E3): The I/O operation has been aborted because of either a thread exit or an application request
at System.Web.WebSockets.WebSocketPipe.<>c__DisplayClass9_0.<ReadFragmentAsync>b__0(Int32 hrError, Int32 cbIO, Boolean fUtf8Encoded, Boolean fFinalFragment, Boolean fClose)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.WebSockets.AspNetWebSocket.<DoWork>d__45`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.WebSockets.AspNetWebSocket.<>c__DisplayClass36_0.<<ReceiveAsyncImpl>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.SignalR.WebSockets.WebSocketMessageReader.<ReadMessageAsync>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNet.SignalR.WebSockets.WebSocketHandler.<ProcessWebSocketRequestAsync>d__25.MoveNext())
以及客户端的WebSocket错误:
SCRIPT12030: WebSocket Error: Network Error 12030, The connection with the server was terminated abnormally
[time] SignalR: Unclean disconnect from websocket:
[time] SignalR: Closing the Websocket.
当我在引发jQuery.signalr-2.2.1.js,事件时选中时,错误代码是1000。
我还在SignalR网站上提出了一个问题。如果你能提出任何办法找出这件事发生的地点/原因,我将不胜感激。
更多信息:
发布于 2017-04-03 04:53:30
我终于找到了解决这个问题的办法。我试图在Bin文件夹中进行以下更改:
string directory = Server.MapPath("~/bin/") + @"\";
string source = directory + @"Templates\Template.xlsx";
string destination = directory + @"Spreadsheets\output file.xlsx";
System.IO.File.Copy(source, destination, true);
导致IIS回收应用程序域,因此,SignalR连接重置并引发WebSocketException。因此,将第一行更改为:
string directory = Server.MapPath("~/") + @"\";
解决了我的问题。
https://stackoverflow.com/questions/43164272
复制相似问题