Surya sasidhar
Surya sasidhar

Reputation: 30303

Thread was being aborted Error ? In asp.net?

In web application, i am using code, to download the documnet which is uploaded, which is written in item command event of datalist, but it s giving error like "Thread was being aborted" can you help me to solve this, thank you. My code is as 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
   {

    }
}

Upvotes: 1

Views: 9637

Answers (4)

Ian Kemp
Ian Kemp

Reputation: 29849

The issue is that you're calling Response.End() before Response.Flush(). Swap the order of those statements and the issue will go away.

Upvotes: 0

Colin Mackay
Colin Mackay

Reputation: 19175

Your Response.End() is most likely what is causing that. It is because it is telling ASP.NET that the request is over.

What is the stack trace from the Exception, where does .NET think the exception is being thrown from?

Upvotes: 1

John
John

Reputation: 3546

You sure that doesn't happen in other code not shown ? usually you get that with when you redirect while inside a try-catch

Upvotes: 0

Alex
Alex

Reputation: 6149

It seems that the file is big so the IIS is killing the thread, you should change this in the web.config:

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

maxRequestLength is in bytes

executionTimeout is in seconds

Upvotes: 2

Related Questions