An HTTP handler is the .net class that executes whenever you make a request for file at certain path.
Each type of resource we can request from an ASP.NET application has a corresponding handler.
When to Use HTTP Handler:
1. if you have to store image in database and you want to display that image in normal HTML tag then you can use handler file.
2. Imagine that you want to expose an RSS feed from your website. In that case, you can create a RSS HTTP Handler that displays a list of blog entries or articles hosted on your website.
3: if you have to display resume or text file which has been stored in database as binary format then you use HTTP handler.
4.If you are looking to avoid the asp.net page life cycle to enhance the performance then you can use HTTP handler.
5. If you want to bridge the cross domain gap then you can use HTTP Handler like this post
How to Create HTTP handler in asp.net ?
Step1: Right Click on Solution Explorer and add the “Generic Handler” file like this
Step2:Write the code in Handler file like this
using System;
using System.Web;public class Handler : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = “image/jpeg”;
context.Response.WriteFile(“Img/cal.jpg”);
}public bool IsReusable {
get {
return false;
}
}}
Step3: Call the handler file in HTML or aspx page like this
<img src="Handler.ashx" height="500px" width="500px" alt=""/>
Step4: Compile the code then you will get op like this
Type of Handler:
There are 2 type of handler
1.Generic or Synchronous Handler
2.Asynchronous Handler
What are the advantages of HTTP Handler ?
There are following advantage of HTTP Handler
1.we can use in cross domain scenario
2.We can call the HTTP handler using html tag.
3.Here is no page life cycle like asp.net page, so it will give good performance while fetching image or data from database.
4.We can easily create RSS feed using HTTP Handler.
5.We can easily fetch image or text file from database.
I every time emailed this blog post page to all my contacts, since if like to read it then my links will too.
Heya i am for the first time here. I found this board and I in finding It really
helpful & it helped me out much. I’m hoping to give something back and aid others like you helped
me.