http handlers

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?
 
H

hb

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.
 
G

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.
 
A

Author

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top