page.aspx.cs code:
HttpContext.Current.Session["id1"] = id1.ToString();
Server.Transfer("Handler.ashx"); //Getting error
Image1.ImageUrl = "~/Handler.ashx?ID=" + id1.ToString();
HttpContext.Current.Session["id2"] = id2.ToString();
Server.Transfer("Handler.ashx"); //Getting error
Image2.ImageUrl = "~/Handler.ashx?ID=" + id2.ToString();
Handler.ashx code:
public void ProcessRequest(HttpContext context)
{
int id = Convert.ToInt32(context.Session["id1"]);
byte[] IMG = class.ReadImg(id);
context.Response.ContentType = "image/jpg";
context.Response.BinaryWrite(IMG);
}
public void ProcessRequest2(HttpContext context2)
{
int id = Convert.ToInt32(context2.Session["id2"]);
byte[] IMG2 = class.ReadImg(id);
context2.Response.ContentType = "image/jpg";
context2.Response.BinaryWrite(IMG2);
}
page.aspx code:
<asp:Image ID="Image1" runat="server" />//How to define thats gonna show image of id1
<asp:Image ID="Image2" runat="server" />//How to define thats gonna show image of id2
Question:
- I’m not able to transfer data from page.aspx to Handler.ashx
- I dont know how to make
Imageelement to identify which image it should show according to the id (maybe somerequest.queryStringmagic I don’t understand)
Help!!
Thanks :]
Server.Transfer() does what it says – transfer the request on the server-side, without returning a HTTP 301 re-direct to the client.
Your problem can be solved by simply reading the querystring in the ashx file:
Then in your aspx page: