views:

284

answers:

3

This is probably very simple but it's really confusing me. When I implement the IHttpHandler, I create a handler and then register it like so in the web.config:

IIS6 Portion:
<httpHandlers>
    <add verb="*" path="*.randomextension" type="MyProgramNameSpace.MyHandler" />
</httpHandlers>

IIS7 Portion:
<handlers>
    <add name="mine" verb="*" path="*. randomextension" type ="MyProgramNameSpace.MyHandler" />
</handlers>

It seems to work quite well and get to use different handlers and options for it. It let's me skip the Page class and so forth by directly accessing the pipeline. However, every so often I keep running into documentation where it says I need to use something about ashx or axd with something.

What is all this about? How does this have to do w/ handler creations?

This is probably very easy but for some reason I'm completely confused when going about this ashx or axd handler.

+4  A: 

The .asxh handler is simply a pre-existing/pre-defined generic handler mapping. Unlike the .aspx handler, you are not restricted to deriving from Page, and you don't get the full ASP.NET page handler event pipeline. Generally, you use .ashx files to handle non-page requests that take as input or return as output non-standard content.

The different from an .ashx handler and a custom IHttpHandler is not much, really. A lot of configuration is predefined for .ashx files, but, you are bound to that extension. With a full custom IHttpHandler, you have complete and total freedom, but need to configure it from the ground up.

jrista
+1  A: 

If you are deciding to use the extension by file type your handler is appropriate.

If on the other hand, you are trying to return data, without a particular extension, the ashx/ahd extension is just as good.

For example, if you have a collection of images stored in a database, you could register a .JPG handler, that would pull the image from the database instead of the hard drive. You could also create an ASHX that could return any image type.

Registering an extension could make the url look more "normal" to the end user, while an ashx looks more generic (even geeky).

Brad Bruce
+1  A: 

There really isn't a difference. .ashx files implement IHttpHandler just like you are doing. Only .ashx is a pre-registered handler so you don't need to add it to the web.config yourself it's already done for you.

olle