更新时间:2021-11-21 02:44:34
您可以创建一个HttpHandler(ASHX)页面这将需要一个查询字符串,并设置为图像控件的ImageUrl属性
You can create an HttpHandler(ashx) page which would take a querystring and set that as the imageUrl property of the image control
<asp:image id="imgEmployee" imageUrl="DisplayImage.ashx?employeeId=<someId>"/>
现在在DisplayImage.ashx,您可以覆盖的ProcessRequest如下图所示: -
Now in DisplayImage.ashx, you can override the Proces-s-request like below:-
public void ProcessRequest (HttpContext context)
{
int employeeId;
if (context.Request.QueryString["employeeId"] != null)
employeeId = Convert.ToInt32(context.Request.QueryString["employeeId"]);
else
throw new ArgumentException("No parameter specified");
byte[] imageData= ;// get the image data from the database using the employeeId Querystring
Response.ContentType = "image/jpeg"; // You can retrieve this also from the database
Response.BinaryWrite(imageData);
}
Web.config中的变化: -
Web.config changes:-
<httpHandlers>
<add verb="*" path="img/*" type="DisplayImage"/>
</httpHandlers>
希望这有助于..