Tuesday, 19 July 2011

How to use HttpHandler using ASP.NET 2.0 and VB.NET


This example demonstrates how to use HttpHandler technology using Asp.Net2.0 and VB.NET

This example demonstrates how to use HttpHandler technology using Asp.Net2.0 and VBNet.

This tutorial only using the default namespace. The System namespace contains the EventHandler.

HttpHandler is class that implement the IHttpHandler and IHttpAsyncHandler interfaces. This section describes how to create and register HttpHandler and provides examples of a synchronous handler, an asynchronous handler, and a handler factory.

First, you need to create a classlibrary HttpHandlerDLLVB. The code as follows:

Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Web
Imports System.Web.SessionState

Namespace HttpHandlerDLLVB
Public Class MyHttpHandlerVB
Implements IHttpHandler, IReadOnlySessionState
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return True
End Get
End Property

Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
context.Response.Write("<h1><b>HttpHandler Test</b></h1>")
context.Session("Test") = "Invoke a session in HttpHandler."
context.Response.Write((context.Session("Test") + "<br>"))
context.Response.Write("<a href='HttpHandlerVB.aspx'><b>return</b></a>")
End Sub
End Class
End Namespace

I just signed up at Server Intellect and couldn't be more pleased with my Windows Server! Check it out and see for yourself.

Then create a website project and reference classlibrary  HttpHandlerDLLVB.dll.

At last configure your web.config as follows.

<httpHandlers>
<add verb="*" path="ViewHttpHandler.aspx" type="HttpHandlerDLLVB.HttpHandlerDLLVB.MyHttpHandlerVB,HttpHandlerDLLVB"/>
</httpHandlers>

Server Intellect assists companies of all sizes with their hosting needs by offering fully configured server solutions coupled with proactive server management services. Server Intellect specializes in providing complete internet-ready server solutions backed by their expert 24/365 proactive support team.

The front end HttpHandlerVB.aspx page looks something like this:

<a href="ViewHttpHandler.aspx">Test HttpHandler</a></p>
</div>

We are using Server Intellect and have found that by far, they are the most friendly, responsive, and knowledgeable support team we've ever dealt with!

The flow for the code behind page is as follows.

Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ASP.NET Tutorials
End Sub
End Class

Looking for the C#.NET 2005 Version? Click Here!

Looking for more ASP.NET Tutorials? Click Here!

No comments:

Post a Comment