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); }
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"
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() }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With