Tuesday, May 6, 2008

HttpHandlers

HttpHandlers may be usefull for specific kind of responses,with asp.net engine...for example for images IIS normally reads the image from file and sends it to browser,and browsers cache this kind of data so at run time you may need to change an image but this may not to presented client without refreshing all page...For this problem we may generate an HTTPHANDLER and take asp.net server to response image files...here is the handler class..and also there are steps over IIS management to accomplish this task...

public class ImageHandler:IHttpHandler
{

public ImageHandler()
{ }


#region IHttpHandler Members

public bool IsReusable
{
get { return false; }
}

public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "image/jpeg";
context.Response.Clear();
context.Response.WriteFile(context.Request.PhysicalPath);
context.Response.End();
}

#endregion



}
On IIS Server
Open Configuration settings,On Mappings tab click Add
In This dialog set executable as %RootFolder%/windows/framevork/%version%/aspnet_isapi.dll
and extension as *.jpg
and undo check the "check that file exists"
than click apply.

On Web Site's web.config folder

add



in the block

Links Article


target="_blank">look this one

No comments: