.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

What is the handlers ? And What are the uses of Handlers ?

Posted By: Sandip Narawade     Posted Date: August 23, 2012    Points:5   Category :ASP.Net
Handler Details

Author: Baimey Rajesh             
Posted Date: August 23, 2012     Points: 20   

What Handlers do you want?

Author: Baimey Rajesh             
Posted Date: August 23, 2012     Points: 20   

It can dynamically return an image from a query string, write XML, or any other data.
ASHX code-behind file [C#]

<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;

public class Handler : IHttpHandler {

public void ProcessRequest (HttpContext context) {
// Comment out these lines first:
// context.Response.ContentType = "text/plain";
// context.Response.Write("Hello World");

context.Response.ContentType = "image/png";

public bool IsReusable {
get {
return false;

Author: Baimey Rajesh             
Posted Date: August 23, 2012     Points: 20   

Please check this site for explanation on

Author: Baimey Rajesh             
Posted Date: August 23, 2012     Points: 20   

Follwing are some of uses of handler file(.ashx) in asp.net:

1. Apply security mechanism,
2. URL rewriting,
3. Filter something in the request that is send to IIS.

Please let me know if you know any more uses of .ashx file.

Author: Baimey Rajesh             
Posted Date: August 23, 2012     Points: 20   

Httphandlers ASP.NET 2.0

Class UrlHandler implements IhttpHandler interface and implements two methods. IsReusable() and ProcessRequest(). The code in process request checks that if current request contains folder name "Users" in it, then retrieve the string after the folder name and remove .aspx extension to get username. Then it displays the user name. In real scenario, the user name can be looked into database, verified and load user specific data.

using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
namespace MyHandler
class UrlHandler : IHttpHandler
#region IHttpHandler Members
public bool IsReusable
get { return false; }
public void ProcessRequest(HttpContext context)
string vPath = context.Request.RawUrl;
//The hard coded value for path can be put in config file to create rules
int vIndexOfFolder = vPath.IndexOf("/users/", StringComparison.OrdinalIgnoreCase);
if (vIndexOfFolder > 0)
string vUserName = vPath.Substring(vIndexOfFolder + 7);
//remove .aspx extension
vUserName = vUserName.Substring(0,vUserName.Length - 5);
context.Response.Write("Welcome " & vUserName);

<httpHandlers >
<add verb="*" path="users/*.aspx" type="MyHandler.UrlHandler,MyHandler" />

Author: Mobile App Developer             
Posted Date: August 23, 2012     Points: 20   

Is ASP.NET ASHX Handler can be used for URL redirection?...301, 302..etc.

Author: BitWise             
Posted Date: August 24, 2012     Points: 20   
Author: kumar             
Posted Date: August 27, 2012     Points: 20   

Can show custom HTML in webpage when page having restricted access and dynamically shows image content

actually display data in browser after processing logic using handler or aspx in the Asp.net dll file in iis

to create handlers simply add http handlers under configuration in web.config file

context object needs to use for dynamic image display

Author: Ravi Ranjan Kumar             
Posted Date: August 31, 2012     Points: 20   

Please be quite clear while asking question. just writing Handler details doesn't means your Intention of question. whatever you have already got so many links and answer. please feel free to revert back with appropriate question. We will be glad to help you.

Thanks & Regards
Ravi Ranjan Kumar

Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend