Hi,

im currently testing the website i created. i used a method of displaying the image through FileStream and BinaryReader (e.g "http://localhost/img.aspx?id=test.jpg"). it works fine actually, but the thing is, everytime i navigate through pages the image reload as well, taking a hit on the page load time.

question:
is there a way to cache the image. so once it's loaded before, it won't stream anymore and will use the cache instead? thanks and hope someone could help me.

Recommended Answers

All 5 Replies

r u loading data using .ashx ?

if no then you can cache the querystring...
depend on that it will cache the image..!

put this on the page level..
<@outputcache varybyParam="id" duration="time of your choice">

im loading data via aspx Page Load response. i'll check if this is applicable. will try first :)

hopefully it should work...wot do u got..?

still looks the same. the picture still load page after page. :| the code of aspx file is this:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="img.aspx.vb" Inherits="user_img" %>
<%@ OutputCache VaryByParam="id" Duration="3600" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    </div>
    </form>
</body>
</html>

then on the page load:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Request.QueryString("id") IsNot Nothing Then
                DisplayImage(Request.QueryString("id"))
        End If
    End Sub

DisplayImage is the file streamer :)

i did it right? yes?

yes u did right but to check the o/p
you need to enable trace option at page level;

so you can see if the page is cached..!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.