TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
gopal vinnamala
NA
136
9.3k
Error in Retrieving Binary Image using generic Handler
Jan 23 2015 7:29 AM
public class Handler : IHttpHandler
{
static DataTable dt;
string url = ConfigurationManager.AppSettings["ServiceUrl"].ToString();
public void ProcessRequest(HttpContext context)
{
string id = context.Request.QueryString["id"];
if (id != null)
{
MemoryStream memoryStream = new MemoryStream();
string json = class.HttpGet(url + "Services/Product.svc/ProductByRowID/" + id);
json = Regex.Unescape(json);
dt = (DataTable)JsonConvert.DeserializeObject(json.Trim(new Char[] { ' ', '"', '.' }), typeof(DataTable));
//Get Image Data
byte[] file = (byte[])Convert.FromBase64String(dt.Rows[0]["ProductImage"].ToString());
context.Response.ContentType = "image/jpg";
context.Response.OutputStream.Write(file, 78, file.Length - 78);
memoryStream.Write(file, 0, file.Length);
context.Response.Buffer = true;
context.Response.BinaryWrite(file);
context.Response.Flush();
context.ApplicationInstance.CompleteRequest();
memoryStream.Dispose();
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
and in .aspx I tried to access the image files as
<asp:Image ID="Image" runat="server" ImageUrl='<%# "Handler.ashx?id=" + Eval("ProductRowId")%>' />
Reply
Answers (
1
)
ASP.NET Cookieless Session- Whats the Role of Server?
Multiples filters: should be wront codes. Which solution?