使用C#在ASP.net中显示数据库中的图像
发布时间:2020-12-16 01:21:36 所属栏目:百科 来源:网络整理
导读:我知道很多次都会问过这种问题. 但我没有成功在页面上显示我的数据库中的图像. 我尝试了以下方法. protected void Page_Load(object sender,EventArgs e) { //Get the picture id by url //Query here byte[] picture = queryoutput; Response.ContentType =
我知道很多次都会问过这种问题.
但我没有成功在页面上显示我的数据库中的图像. 我尝试了以下方法. protected void Page_Load(object sender,EventArgs e) { //Get the picture id by url //Query here byte[] picture = queryoutput; Response.ContentType = "image/jpeg"; Response.BinaryWrite(picture); } 链接获取图像. <asp:Image runat="server" ImageUrl="~/givememypicture.aspx?pic=3" ID="testimage" /> < asp:Image />标签位于< asp:Content>之间标签. 当我运行此代码并检入firebug时,它只是声明“无法加载fiven URL”. 我是asp.net的新手,但我在c#方面有一些经验. 如果我可以通过同一页面的代码文件填写图片,那将是最好的.调用另一个页面来加载图像对我来说似乎很不合逻辑. 有人可以告诉我这里我做错了什么吗? 解决方案:从处理图像响应的页面上的页面指令中删除了母版页引用.除了aspx文件中的@page指令本身之外,还删除了其他所有内容. 解决方法
尝试使用一个处理程序文件(.ashx)把你的page_load中的代码放在那个谎言中
public void ProcessRequest (HttpContext context) { //Get the picture id by url //Query here byte[] picture = queryoutput; Response.ContentType = "images/jpeg"; Response.BinaryWrite(picture); } public bool IsReusable { get { return false; } } 然后调用处理程序文件并从中传递正确的查询字符串项 这应该工作 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |