首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >句柄无效。(HRESULT例外: 0x80070006 (E_HANDLE))

句柄无效。(HRESULT例外: 0x80070006 (E_HANDLE))
EN

Stack Overflow用户
提问于 2011-10-12 11:43:47
回答 8查看 69.4K关注 0票数 23

我在IIS 7共享主机环境中有一个网站。它运行的是.NET 3.5。我有一个下载按钮从服务器下载一个文件。

当我在本地将此应用程序部署到IIS 6时,它运行良好。在IIS 7共享宿主服务器上,会发生异常。

句柄无效。(来自HRESULT: 0x80070006 (E_HANDLE)的异常)描述:在执行当前web请求期间发生了未处理的异常。请查看堆栈跟踪以获得有关错误的更多信息,以及它起源于代码的位置。

System.Runtime.InteropServices.COMException:句柄无效。(HRESULT例外: 0x80070006 (E_HANDLE))

COMException (0x80070006):句柄无效。( HRESULT: 0x80070006 (E_HANDLE)例外)] HttpException (0x80004005):与远程主机通信时发生错误。错误代码为0x80070006。

如何解决这一问题?

代码语言:javascript
复制
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);
}
EN

Stack Overflow用户

发布于 2013-11-19 19:48:05

我在下面的链接中找到了一个修复方法:

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

代码语言:javascript
复制
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()


}
票数 13
EN
查看全部 8 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7739543

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档