Sal*_*Roy 19 c# asp.net iis-7 shared-hosting httpexception
我在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);
}
Run Code Online (Sandbox Code Playgroud)
小智 14
创建一个.bat文件,输入以下命令并运行该文件.它将终止所有现有的Web服务器进程,并应该解决问题.我有同样的问题,它对我有用.非常感谢
taskkill /fi "imagename eq webdev.webserver40.exe"
Run Code Online (Sandbox Code Playgroud)
小智 12
我从以下链接找到了修复:
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()
}
Run Code Online (Sandbox Code Playgroud)
编辑:错过了最初有关页面加载的部分。我不太确定从查询字符串传入的内容是什么,但是您尝试过使用 Server.MapPath 吗?所以而不是
System.IO.FileInfo file = new System.IO.FileInfo(strRequest);
Run Code Online (Sandbox Code Playgroud)
你有
System.IO.FileInfo file = new System.IO.FileInfo(Server.MapPath(strRequest));
Run Code Online (Sandbox Code Playgroud)
让我知道这是否有帮助。
| 归档时间: |
|
| 查看次数: |
55311 次 |
| 最近记录: |