http handlers

  • Thread starter Thread starter hb
  • Start date Start date
H

hb

I have created an HTTP Handler. For simplicity of testing, it is:

public class FetchItem : IHttpHandler
{
public bool IsReusable { get { return true; } }
public void ProcessRequest(HttpContext context)
{
context.Response.Write("Unable to retrieve file");
context.Response.ContentType = "plain/text";
context.Response.Flush();
context.Response.Close();
}
}

This is in a sub folder (img) of my web application with a web.config:
<?xml version="1.0"?>
<configuration>
<system.web>
<httpHandlers>
<clear/>
<add verb="*" path="*.jpg" type="FetchItem"/>
</httpHandlers>
</system.web>
</configuration>

My intent is to allow retrieving images from a database, though I want to
use the requested item to define the item in the database so requests like:
http://server/img/1.jpg
or
http://server/img/latest/picture.jpg
could be processed. Notice the addition of a directory in the second
example. Now, in my debug environment, I have no problem. Though when I
try to move the application to a godaddy web server, it just dies.
The web server has two behaviors.
A request in the first form returns the content of the default web site page
(i.e. http://server/default.htm), though the address bar still reads the
original request (i.e. it doesn't look like a redirect).
A request in the second form returns a server error #500

One difference is that in my debug enviornment, I am running IIS 5.1 (on
windows XP) while on the godaddy server it is IIS 7.0.

Any suggestions?
 
It appears that I am unable to sort though the IIS documentation. The
proper web.config is:
<?xml version="1.0"?>
<configuration>
<system.webServer>
<handlers>
<add verb="*" path="*.jpg" name="FetchItem" type="FetchItem"/>
</handlers>
</system.webServer>
</configuration>
Sorry for the trouble everyone.
 
You will have problem with this...
In order for you handler to run the IIS must send request through ASP.NET
engine.
It onyl does by extension.

So *.aspx will be send through ASP.NET, *.ashx will be as well
*.jpg will not, IIS will server the requested jpeg file without touching
web.config and your handler.

George.
 
You will have problem with this...
In order for you handler to run the IIS must send request through ASP.NET
engine.
It onyl does by extension.

So *.aspx will be send through ASP.NET, *.ashx will be as well
*.jpg will not, IIS will server the requested jpeg file without touching
web.config and your handler.

George.

That's right, but we can also register *.jpg extension with
aspnet_isapi.dll, right?
 
Back
Top