Introducing HTTPHandlers
page 4 of 4
by . .
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 26263/ 39

ASHX Files
ASHX Files

Now, if all of that web.config stuff was just a bit too much then you don't have to live with it. If you check the IIS mappings tab you will see that there is a file extension - .ashx this extension is the extension for a HTTPHandler File. This takes out all of that lovely web.config stuff and IIS config that you have to do.

For example here is time.ashx -

<%@ WebHandler Class="HttpModHan.SampleHandler" %>
Imports System
Imports
System.Web

Namespace
HttpHanMod
Public
Class SampleHandler : Implements
IHttpHandler

Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim
thetime As DateTime = DateTime.Now.Subtract(New
TimeSpan(12, 0, 0))
Dim
gmtplus As Double = CInt(context.Request.QueryString("gmtplus"))

thetime = thetime.AddHours(gmtplus)

context.Response.ContentType = "text/xml"
context.Response.Write("<time>")
context.Response.Write("<GMT>")
context.Response.Write(thetime.ToString())
context.Response.Write("</GMT>")
context.Response.Write("</time>")

End
Sub

Public ReadOnly Property IsReuseable() As Boolean Implements IHttpHandler.IsReusable
Get
Return True
End Get
End Property
End Class

End Namespace

Live Demo

You may also notice that if you add ?gmtplus=xxx (where xxx is hours past GMT) it adds it to the answer.

If you check the documentation for ASHX files, you will find nothing on them.

Summary

This article has shown you how to create and use HTTPHandlers, both in Assemblies and in ASHX files. Be sure that there will be more articles on HTTPHandlers (hence the "Getting Started" in the title), but in the mean time check out the Related Articles for more information on this whole ASP.NET Pipeline.


View Entire Article

User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-25 10:59:09 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search