线程被中止错误?在asp.net中?

线程被中止错误?在asp.net中?,asp.net,Asp.net,在web应用程序中,我正在使用代码下载上传的documnet,这是在datalist的item command event中编写的,但它会出现“线程被中止”之类的错误。您能帮我解决这个问题吗,谢谢。我的代码是fallows protected void dtlstMagazine_ItemCommand(object source, DataListCommandEventArgs e) { try { objItMagBe.TitleId = Convert.ToInt

在web应用程序中,我正在使用代码下载上传的documnet,这是在datalist的item command event中编写的,但它会出现“线程被中止”之类的错误。您能帮我解决这个问题吗,谢谢。我的代码是fallows

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
   {

    }
}

似乎文件很大,因此IIS正在终止线程,您应该在web.config中更改此选项:

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

maxRequestLength以字节为单位


executionTimeout以秒为单位

您确定在未显示的其他代码中不会发生这种情况吗?通常,当您在try-catch中重定向时,您的响应会出现这种情况。End()很可能是导致这种情况的原因。这是因为它告诉ASP.NET请求已结束


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

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

ya try catch就在那里,但我不认为这里是john先生的回答。End()按照科林的建议,试着删除那一行。