All About ASP.NET and ASP.NET Core 2 Hosting BLOG

Tutorial and Articles about ASP.NET and the latest ASP.NET Core

ASP.NET 4.5 Hosting :: How to Writing HTTP Handler in IIS 7.5

clock September 4, 2013 05:46 by author Mike

A handler is associated with a particular type resource. It may be mapped to only a given resource. Handler mappings may also be restricted by a Http verb which means you may want to only work with GET requests ( for example if you Http handler is only supposed to send back images) or a POST request ( for example if you collect some data on the given handler).

We should code a custom Http handler if and only if the resource type to be accessed is fairly customized and is a separate entity on you system The Http response generation logic weather visible or not is very different from a regular aspx pages. In these cases it should be observed that the request should not be part of a page lifecycle.

With IIS 7.5 and beyond it is being tried that as far as possible the config definition should be available in the web.config file of an ASP.NET web site. Handlers can be configured using the IIS wizard or by directly editing the web.config file.

This article describes how handlers are to be written and configured in IIS 7.5.

Any managed http handler implements the IHTTPHandler interface.

public class TextHandler :IHttpHandler

The Http handler has a very important property IsReusable. The purpose of this property is to define if the instance of the Http handler can be shared or not. The IsReusable property should return true if and only is there is no field in the handler which can define the state. If we make IsReusable as false then the performance is slower.

bool IHttpHandler.IsReusable{
get { return true; }


The other method of interest is Process request, the objective of this method is to generate any valid Http response (not html response).

void IHttpHandler.ProcessRequest(HttpContext context)

StringBuilder htmlText = new StringBuilder();
htmlText.Append("Sample Text");

Configuration of Http handlers follows similar mechanism as modules. Handlers can be configured by using web.config or using the IIS manager. If you use web.config, you can use listing below.

<add name="TextHandler" path="*.Text" verb="*" type="TextHandler" resourceType="Unspecified" preCondition="integratedMode" />

In the system.webServer section add a handlers section. In this add a new handler. The name is a unique name for the handler. The path contains the path on the server. It can be wild card or an absolute path. In this example the value can be *.Text or Static.Text. The value of verb can be * or a comma separated set of verbs such as GET, POST, PUT, DELETE or any verbs used for this handler.

The type is the fully qualified name of the class in which the handler code is written. It should be noted that a precondition here is integratedMode.

If you use IIS Manager, follow steps below.

1. Open IIS Manager
2. Expand the node of your web application
3. Open the Handler Mapping feature


4. Click on Add managed handler


5. Add the various values


6. Click on request restrictions and add values for verbs


Some pitfalls

  1. Session is not available: The HttpSessionState is a module in itself hence we should ensure that when creating a module we will not have access to Http Session.
  2. Http request is read only: The various elements of the Http request such as query strings in modules are readonly. It should be noted that the url is not read only and you can create modules for Url rewrite.
  3. Http handler IsReusable: The IsReusable property is a death trap for the novice programmer. Great care should be taken to decide the value of IsReusable. It should be noted that as far as possible we should try to keep our handler stateless in interest of performance.

ASP.NET 4.5 Hosting – :: How To Filter Data With Model Data Binding In ASP.NET 4.5

clock September 2, 2013 12:33 by author Ben

Are you looking for a solution to filter your data using the Data Model Binding in ASP.NET 4.5? Maybe these tips can help you.

Earlier versions of ASP.Net have the ObjectDataSource Control but ASP.NET 4.5 has integrated it with Data Controls. New properties are included in ASP.NET 4.5 such as SelectMethod, UpdateMethod and DeleteMethod.

The following is a way to filter the data to the data model binding in ASP.NET 4.5 :

First of all create a new Web Application in V.S 2012.

2. Now add the Grid View to your Web Page. I have create a basic model class “Employee” like below.

3. This class contains three properties EmployeeId,FirstName and LastName. And create one method to get a generic list of employee model like following.

4. Now it’s time to use “SelectMethod” attribute like following.

5. After that you can run this program.

You can also do the filtering with the Select Method very easily. Here to demonstrate the filtering let’s take a dropdown list  control like following and based on the dropdown list control selected item we will filter our grid view with select method.

1. Follow this HTML Code

2. Now let’s modify your GetEmployees method like following to filter based on dropdownlist control.

3. Now let’s run the example again.

Cheap ASP.NET 4.5 Hosting

We’re a company that works differently to most. Value is what we output and help our customers achieve, not how much money we put in the bank. It’s not because we are altruistic. It’s based on an even simpler principle. "Do good things, and good things will come to you".

Success for us is something that is continually experienced, not something that is reached. For us it is all about the experience – more than the journey. Life is a continual experience. We see the Internet as being an incredible amplifier to the experience of life for all of us. It can help humanity come together to explode in knowledge exploration and discussion. It is continual enlightenment of new ideas, experiences, and passions

Author Link

 photo ahp banner aspnet-01_zps87l92lcl.png


Corporate Address (Location)

170 W 56th Street, Suite 121
New York, NY 10019
United States

Tag cloud

Sign in