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
Majid Kamali
NA
290
256.2k
Check my Code
Jul 18 2011 3:58 AM
Hi.
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
<add verb="*" path="*.png" type="Nokhbegan_New.Class1"/>
Reply
Answers (
3
)
Newsletter subscription with ajax dialog box
How do I count the number of accounts present in Microsoft Outlook 2010?