![](/img/trans.png)
[英]How does HttpContext.Current.Response.Binarywrite work?
[英]How does the binarywrite() method works?
我有.ashx文件中的以下代码行。
public void ProcessRequest (HttpContext context)
{
string hstr = @"Data Source=SUMAN-PC\SQLEXPRESS;Initial Catalog=school;Integrated Security=True";
SqlConnection con = new SqlConnection(hstr);
string ms = context.Request.QueryString["id_image"].ToString();
con.Open();
SqlCommand cmd = new SqlCommand("select img from class where classid=" + ms, con);
SqlDataReader dr = cmd.ExecuteReader();
dr.Read();
context.Response.BinaryWrite((Byte[])dr[0]);
context.Response.End();
}
经过研究,我发现了这个
“ BinaryWrite方法将特定数据发送到当前的HTTP输出,而无需任何字符转换。”
这是什么意思? 它如何将数据发送到http输出? HTTP输出在哪里?
在这种情况下, context.Response
是代表代表发送到发出HTTP请求的客户端(最有可能是Web浏览器)的数据的流。 幕后的ASP“引擎”会自动向您提供Context.Response
。 您写入该流的所有内容最终都会发送到浏览器。
通用的http处理程序会自动为您提供一个名为Context
的HttpContext实例。 HttpContext包含两个名为Request和Response的属性,这些属性使您可以访问通用处理程序正在服务的请求和相应的响应。 处理程序应进行所需的任何处理,并通过将其回复写入Response流来发送结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.