相关疑难解决方法(0)

接受的方法可以防止"远程主机关闭连接"异常

经常遇到以下异常,这是由用户启动下载引起的,因此失败(或被取消):

错误消息:远程主机关闭了连接.错误代码是0x80072746.堆栈跟踪:在System.Web.Hosting.ISAPIWorkerRequestInProcForIIS6.FlushCore(Byte []状态,Byte []标头,Int32 keepConnected,Int32 totalBodySize,Int32 numBodyFragments,IntPtr [] bodyFragments,Int32 [] bodyFragmentLengths,Int32 doneWithSession,Int32 finalStatus,Boolean& System.Web.Hosting.ISAPIWorkerRequest.FlushResponse(Boolean finalFlush)at System.Web.Hosting.ISAPIWorkerRequest.FlushCachedResponse(Boolean isFinal)atync)

我在互联网上搜索过,发现了一篇有趣的文章,但似乎没有一个明确的答案,因为这是防止这种填充日志的最佳方法.

用户没有看到任何错误,并且在应用程序中没有实际问题,因为它仅在我的理解中发生(在我的理解下)在其无法控制的情况下(用户取消下载或丢失连接)但是必须有一种方法来防止这样的异常报道.

我不想这么说但是我很想检查这个异常并且空了阻止它的屁股 - 但这让我觉得自己像个肮脏的程序员.

那么 - 防止此异常填满我邮箱的可接受方法是什么?

.net c# asp.net exception-handling exception

9
推荐指数
2
解决办法
7371
查看次数

例外:"远程主机关闭连接.错误代码为0x80070057"

我得到了这个例外.我遵循了这个错误意味着什么的建议 ?远程主机关闭了连接.错误代码是0x80070057

不过,我得到了同样的错误.

我正在使用一个文件从服务器传输到客户端浏览器Response.WriteFile().

在视图中:

  $("#btnExport").on("click", function (e) {
      window.location = '@Url.Action("ExportToExcel", "Report")';
       e.preventDefault();
  });
Run Code Online (Sandbox Code Playgroud)

在控制器中:

[HttpGet]
public RedirectResult ExportToExcel()
{
    Download(ExportFilePath);    
    return new RedirectResult(ExportFilePath); 
}

public void Download(ExportFilePath)
{
    HttpContext context = System.Web.HttpContext.Current;
    FileInfo file = new FileInfo(ExportFilePath);
    context.Response.Clear();
    context.Response.ClearHeaders();
    context.Response.ClearContent();
    context.Response.AppendHeader("Content-Disposition", "attachment; filename =" + ExportFileName);
    context.Response.AppendHeader("Content-Length", file.Length.ToString());
    context.Response.ContentType = "application/excel";
    context.Response.WriteFile(file.FullName);
    context.Response.Flush();
    context.Response.Close();
    context.Response.End();
}
Run Code Online (Sandbox Code Playgroud)

javascript c# asp.net-mvc

4
推荐指数
1
解决办法
6967
查看次数