【问题标题】:Thread was being aborted Error ? In asp.net?线程被中止错误?在asp.net?
【发布时间】:2012-03-09 08:49:14
【问题描述】:

在Web应用程序中,我正在使用代码下载上传的文档,该文档是在datalist的项目命令事件中编写的,但是它给出了诸如“线程被中止”之类的错误,您能帮我解决这个问题吗?谢谢你。我的代码是休闲的。

protected void dtlstMagazine_ItemCommand(object source, DataListCommandEventArgs e)
{
   try 
   { 
    objItMagBe.TitleId = Convert.ToInt32(e.CommandArgument);
    dts = new DataSet();
    dts = objItMagBL.GetMagzineByTitleID(objItMagBe);
    GetPopularMagazine();

    string Myfile = "../xxxx/DataFiles/" + dts.Tables[0].Rows[0]["Files"].ToString();
    if (File.Exists(Server.MapPath(Myfile)) == true)
    {
        Response.AppendHeader("Content-Disposition", "attachment; filename=" + Myfile);
        Response.TransmitFile(Server.MapPath(Myfile));
        Response.End();
        Response.Flush();
    }
   }
   catch
   {

    }
}

【问题讨论】:

    标签: asp.net


    【解决方案1】:

    文件似乎很大,所以 IIS 正在杀死线程,你应该在 web.config 中更改它:

    <httpRuntime 
        maxRequestLength="1048576"
        executionTimeout="3600"
      />
    

    maxRequestLength 以字节为单位

    executionTimeout 以秒为单位

    【讨论】:

      【解决方案2】:

      您的 Response.End() 很可能是造成这种情况的原因。这是因为它告诉 ASP.NET 请求已经结束。

      异常的堆栈跟踪是什么,.NET 认为异常是从哪里引发的?

      【讨论】:

        【解决方案3】:

        您确定在未显示的其他代码中不会发生这种情况吗?通常,当您在 try-catch 中进行重定向时,您会得到它

        【讨论】:

        • 你试试 catch 在那里,但我没有把它放在这里,约翰先生
        • 可能是 Colin 建议的 Response.End() ,请尝试删除该行。
        【解决方案4】:

        问题是您在Response.Flush() 之前调用Response.End()。交换这些语句的顺序,问题就会消失。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-08-11
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多