C# Response.Flush 远程服务器错误。错误代码:0x80070057

.Net技术 码拜 9年前 (2015-02-09) 1552次浏览 0个评论

文件以二进制byte[]被存储在数据库上,格式是img。前台使用extjs的ajax调用后台函数,
前台extjs代码如下:
pre class=”brush: javascript”>/*
* 数据库文件下载
*/
function DBgridDownload(docID) {
Ext.Ajax.request({
url: “/Url/Load/DownLoad.aspx”,
method: “post”,
params: {
DownLoad: “GetDBDocBase64”,
F_ID: docID
},
success: function (response, options) {
},
failure: function () {
Ext.Msg.alert(“系统提示”, “系统异常,服务器未能响应!”);
}
});
}
前台应该没有啥问题,只是触发个函数而已
后台代码写在Page_Load里边,包含if (!Page.IsPostBack)。具体代码为:
pre class=”brush: csharp”>if (Serach == “GetDBDocBase64”)
{
//GetDocBase64(Request);
Response.Buffer = true;
Model.Load.LOAD_DOC model = new Model.Load.LOAD_DOC();
model = LOAD_DOC_BLL.GetBDDocBase64ByID(Request[“F_ID”]);
Response.AddHeader(“Content-Disposition”, “attachment;filename=” + HttpUtility.UrlEncode(model.F_DOC_NAME, System.Text.Encoding.UTF8));
Response.AddHeader(“Content-Length “, model.F_DOC.Length.ToString());
Response.ContentType = model.F_DOC_TYPE.Remove(0, 1);
Response.BinaryWrite(model.F_DOC);
Response.Flush();
Response.Close();
}
Response.End();
问题在于:当本代码被触发后,程序运行到Flush()部分,会返回到Buffer=true再次执行,多次执行后,系统在flush()报错。报错原因,远程服务器错误。错误代码:0x80070057

C# Response.Flush 远程服务器错误。错误代码:0x80070057
2分
  Response.Buffer = true; 这个不要设置吧。
C# Response.Flush 远程服务器错误。错误代码:0x80070057
引用 1 楼 wyd1520 的回复:

  Response.Buffer = true; 这个不要设置吧。

我去掉了,仍然是那个错误啊!有些帖子说加上。。。

C# Response.Flush 远程服务器错误。错误代码:0x80070057
2分
调试一下 http 消息,看看你的“前台”一共发出了多少次请求。
C# Response.Flush 远程服务器错误。错误代码:0x80070057
引用 2 楼 capaa52007 的回复:
Quote: 引用 1 楼 wyd1520 的回复:

Response.Buffer = true; 这个不要设置吧。

我去掉了,仍然是那个错误啊!有些帖子说加上。。。

在开头加上
Response.Clear(); 这样试试, 要先清空内存里的数据。
Response.AddHeader(“Content-Disposition”, “attachment;filename=” + HttpUtility.UrlEncode(model.F_DOC_NAME, System.Text.Encoding.UTF8));

C# Response.Flush 远程服务器错误。错误代码:0x80070057
引用 4 楼 sp1234 的回复:

调试一下 http 消息,看看你的“前台”一共发出了多少次请求。

我用firebug看了一下,就一个消息啊。就是在控制台看到的 。这段js代码就调用了一层,没有更多的地方啊。。。
难道是response有问题?

C# Response.Flush 远程服务器错误。错误代码:0x80070057
引用

在开头加上
Response.Clear(); 这样试试, 要先清空内存里的数据。
Response.AddHeader(“Content-Disposition”, “attachment;filename=” + HttpUtility.UrlEncode(model.F_DOC_NAME, System.Text.Encoding.UTF8));

我试过,仍然报错!。。。

C# Response.Flush 远程服务器错误。错误代码:0x80070057
16分
引用 4 楼 sp1234 的回复:

调试一下 http 消息,看看你的“前台”一共发出了多少次请求。

首先你要明白response是对响应报文进行封装的对象,里面的大部分属性都是设置http响应报文报文头,它必须遵守http协议报文头的规范,报文体就是你要发送的数据.你要明白了这个道理就不会去这么乱写

C# Response.Flush 远程服务器错误。错误代码:0x80070057
引用 10 楼 capaa52007 的回复:
Quote: 引用 9 楼 woshifyaa 的回复:

fieldset>

Quote: 引用 4 楼 sp1234 的回复:

调试一下 http 消息,看看你的“前台”一共发出了多少次请求。

首先你要明白response是对响应报文进行封装的对象,里面的大部分属性都是设置http响应报文报文头,它必须遵守http协议报文头的规范,报文体就是你要发送的数据.你要明白了这个道理就不会去这么乱写

我想也是 报头写的有问题,我也是差的网络,看来是学艺不精啊 我再查查!
解决了,是报头写的有问题。。
fieldset>

引用
HttpRequest hrRequest = context.Request;
HttpResponse hrResponse = context.Response;
string sDocPath = System.Web.HttpContext.Current.Request.MapPath("~/" + hrRequest["F_DOC_PATH"])+hrRequest["F_DOC_NAME"];
if (!File.Exists(@sDocPath))
hrResponse.Write("[{"success":"false","exception":"文件已被删除或不存在!"}]");
FileInfo fileInfo = new FileInfo(@sDocPath);
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearContent();//
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.Buffer = false;
//通知http前台是下载而不是打开
HttpContext.Current.Response.ContentType = "application/octet-stream;charset=gb2321";
//HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(hrRequest["F_DOC_NAME"], System.Text.Encoding.UTF8));
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + hrRequest["F_DOC_NAME"]);
HttpContext.Current.Response.AddHeader("Content-Length", fileInfo.Length.ToString());
//HttpContext.Current.Response.AddHeader("Content-Transfer-Encoding", "binary");
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("utf-8");
HttpContext.Current.Response.WriteFile(fileInfo.FullName);
HttpContext.Current.Response.Write("[{"success":true}]");
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
/pre>

看来我要学习学习报头了


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明C# Response.Flush 远程服务器错误。错误代码:0x80070057
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!