我有一个位于 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。]
如何解决这个问题?
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);
}
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);
}
发布评论
评论(8)
创建一个 .bat 文件,输入以下命令并运行该文件。它将杀死所有现有的网络服务器进程并应该解决问题。我遇到了同样的问题,它对我来说很有效。非常感谢
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
我从下面的链接找到了修复:
http://forums.asp.net/t/1387967.aspx?How+to+create+a+flipcart+like+panel+for+showing+products+in+gridview
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
我刚刚在我们的环境中解决了这个问题。我们打开了模拟并让应用程序池作为 ApplicationPoolIdentity 运行。
问题是由于应用程序池身份没有对源文件的读取访问权限而引起的,即使模拟的用户确实有权访问该文件。解决这个问题的棘手之处在于,如果用户和应用程序池都没有访问权限,则会出现访问权限错误。
I just resolved this issue in our environment. We have impersonation turned on and have the application pool running as ApplicationPoolIdentity.
Problem was caused by the app pool identity not have having read access to the source file even though the impersonated user did have access to the file. What made this tricky to resolve is that if both user and app pool do not have access you get a access permission error.
编辑:错过了最初有关页面加载的部分。我不太确定从查询字符串传入的内容是什么,但是您尝试过使用 Server.MapPath 吗?因此,
您不必
让我知道这是否有帮助。
EDIT: Missed the part about the page loading fine initially. I'm not exactly sure what's being passed in from your querystring, but have you tried using Server.MapPath? So instead of
you have
Let me know if that helps.
就我而言,我尝试写入和读取该文件:
我使用了下面的代码并且它有效。我认为 IIS 用户缺少写入或读取临时文件的权限。
In my case I was trying to write and read to this file:
I used the code below and it worked. I think that IIS user was missing permission to write to or read from the temporary file.
重新启动 IIS 解决了我的问题。
Restarting IIS solved the issue for me.
如果您的网页中有任何 Console.WriteLine 或 Console.Clear(),则当不在 Visual Studio 中运行时(即当您将其部署到 IIS 时),您可能会收到该错误。
如果您在 IIS 和 VS 中遇到此问题,它工作正常,然后搜索控制台语句并将其删除。
If you have any Console.WriteLine or Console.Clear() in your web pages you might get that error when not running in Visual Studio , means when you deploy it to IIS .
If you get this problem in IIS and in VS it works fine then search for Console statements and remove them .
就我而言,这种情况仅发生在特定用户登录时。其他所有用户都可以正常工作。
问题是用户的 LoginEmail 中存在额外的空格。
这发生在 MVC 应用程序中,该应用程序使用 Asp.net Identity 和 Impersonation 从托管服务器上的目录下载 excel 文件。
奇怪的东西!
In my case this happened for a specific user login only. Every other user had it working.
The issue was an extra white space in the user's LoginEmail.
This happened in an MVC application, which was using Asp.net Identity, and Impersonation to download an excel file from a directory that lives on the hosting server.
Weird stuff!