Dave on Facebook

Dave's profile on LinkedIn
DavesWeb visitors really liked:
Country Place Cookbook
Tomato Sauce Recipe
Bloody AwfulBelow AverageNothing SpecialGoodPretty Damn Good
My Status
Fabulous Snow!
Bloody AwfulBelow AverageNothing SpecialGoodPretty Damn Good
My Status
Thankful for Signs of Spring!
Bloody AwfulBelow AverageNothing SpecialGoodPretty Damn Good
Country Place Cookbook
Grandmother Snare's Iced Tea
Bloody AwfulBelow AverageNothing SpecialGoodPretty Damn Good
Gallery
Can Am Eyes
Bloody AwfulBelow AverageNothing SpecialGoodPretty Damn Good
Top Viewed items on DavesWeb:
My Status
Balsamic Vinaigarette Watermelon - 38,091 views
My Status
Cool car - 26,530 views
Gallery
Can Am Eyes - 25,967 views

No Live Blogging, Sorry - 16,716 views
My Status
Ads Sneaked Onto DavesWeb Part 2 of 2 - 16,252 views
Recently Viewed Items on DavesWeb:
TechQuest
Simple Asp.Net: Using an ASHX Generic Handler
TechQuest
Prettifying Code Snippets on Web Pages
Trailhead
Lovely December Afternoon in Tuscon, Arizona
TechQuest
Taking Embedded Javascript (EJS) For A Test Drive
TechQuest
Simple JavaScript: Add/Hide Html Elements
TechQuest: Welcome to TechQuest.
Simple Asp.Net: Using an ASHX Generic Handler

During development of an AJAX-like web application, I was beginning work on a page that would receive an Xml request and return an Xml response. I learned that I don't want to use a full Aspx page because that would waste resources by forcing IIS to do its full viewstate build-up and tear-down processing. Our page isn't a web-form at all--we just need to do pure Xml processing. An Ashx document was suggested as the ideal solution, but I've never used one.

Using Visual Studio 2010, we begin by adding a new Generic Handler:
Uploaded Image

The default code is straightforward, creating a class with a name that matches the file name. It implements the System.Web.IHttpHandler interface, with the ProcessRequest method simply returning a text message.
Uploaded Image
It works right out of the box. A simple Get request to the file returns the expected message. This should be perfect for my Xml-over-Http demo!

Since the whold reason for using Ashx is performance, I decided to compare this page to a standard Aspx page using www.webpagetest.org.
Uploaded Image
The Ashx page came back in 0.332s. Subsequent tests came back in 0.294s and 0.289s.


Uploaded Image
The Aspx page first came back in 0.680s, twice as slow as the Ashx handler! A second try came back in under 0.3s, probably because IIS was using its pre-compiled copy of the page. It will be interesting to test Ashx performance as the page gets more complicated, but it looks like Ashx is the way to go in implementing my Xml-over-Http handler.

It was tempting to think that I might replace all my aspx pages on this site with ashx, but there are a few circumstances where I do need to use SessionState variables and SessionState is not wired up for ashx requests. It's clear that ashx pages are useful and perform well, but aren't suitable for every circumstance.

2,695 views.
No users have rated this item yet.