Get WebSocket Error: Network Error 12030 when using File.Copy with SignalR

Get WebSocket Error: Network Error 12030 when using File.Copy with SignalR

我下载了 Sample SignalR Progress Bar 解决方案。它在服务器上模拟了一个很长的 运行 进程,使用 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时,当onclose事件引发时,错误代码是1000.

我也在 SignalR website 上提出了一个问题。如果您能提出任何方法来找出 where/why 这正在发生,我将不胜感激。

更多信息:

我终于找到解决问题的办法了。我尝试在此处 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("~/") + @"\";

解决了我的问题。