I have a website that has many png files. so I want to cache them.
please check correctness of my code and mention its problems.
Thanks
// Class1
public class Class1 : IHttpHandler
{
public bool IsReusable
{
get { return true; }
}
public void ProcessRequest(HttpContext context)
{
string file = context.Server.MapPath(context.Request.FilePath);
string filename = file.Substring(file.LastIndexOf('\\') + 1);
context.Response.Cache.SetExpires(DateTime.Now.Add(new TimeSpan(0, 1, 0))); // SET EXPIRATION TO 1 MINUTE, (THIS IS AN EXAMPLE)
context.Response.Cache.SetCacheability(HttpCacheability.Public);
context.Response.Cache.SetValidUntilExpires(false);
context.Response.ContentType = "image/png";
context.Response.AddHeader("content-disposition", "inline; filename=" + filename);
context.Response.WriteFile(file);
}
//Web.config


Amit ChoudharyRank #145 · 15.8K reputationPosted Jul 20, 2011, 1:59 AM EDT
your code Looks fine..
What problem are facing with it?
Majid KamaliRank #6,453 · 266 reputationPosted Jul 20, 2011, 7:14 AM EDT
Anil KumarRank #367 · 6.8K reputationPosted Jul 20, 2011, 10:51 PM EDT