Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The handle is invalid. (Exception from HRESULT: 0x80070006 (E_HANDLE))

Tags:

I have a website in an IIS 7 shared hosting environment. It's running .NET 3.5. I have a download button to download a file from the server.

When I locally deploy this application to IIS 6, it runs fine. On the IIS 7 shared hosting server, the exception occurs.

The handle is invalid. (Exception from HRESULT: 0x80070006 (E_HANDLE)) Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
System.Runtime.InteropServices.COMException: The handle is invalid. (Exception from HRESULT: 0x80070006 (E_HANDLE))
COMException (0x80070006): The handle is invalid. (Exception from HRESULT: 0x80070006 (E_HANDLE))] [HttpException (0x80004005): An error occurred while communicating with the remote host. The error code is 0x80070006.]

How can this be solved?

string strRequest = Convert.ToString(Request.QueryString.Get("file")); System.IO.FileInfo file = new System.IO.FileInfo(strRequest); if (file.Exists) {     Response.Clear();     Response.ContentType = ReturnExtension(System.IO.Path.GetExtension(file.Name));     Response.AppendHeader("Content-Disposition", "attachment; filename=" + file.Name);     Response.TransmitFile(strRequest);     Response.End();     HttpContext.Current.ApplicationInstance.CompleteRequest();     //DownloadFile(file.FullName, file.Name); } 
like image 815
Salman Roy Avatar asked Oct 12 '11 11:10

Salman Roy


2 Answers

Create a .bat file, put the following command and run the file. It will kill all existing webserver processes and should fix the problem. I had the same problem and it worked out for me. Thanks much

taskkill  /fi "imagename eq webdev.webserver40.exe"  
like image 172
asim Avatar answered Sep 21 '22 05:09

asim


I found a fix from link below:

http://forums.asp.net/t/1387967.aspx?How+to+create+a+flipcart+like+panel+for+showing+products+in+gridview

if (file.Name == fileName)  {      Response.ClearContent();      Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);      Response.AddHeader("Content-Length", file.Length.ToString());      Response.TransmitFile(file.FullName);      //Response.End(); Will raise that error. this works well locally but not with IIS      Response.Flush();//Won't get error with Flush() so use this Instead of End()   } 
like image 23
Ricky Avatar answered Sep 20 '22 05:09

Ricky