Hi,

I have a web application with an additional web.config file in a
subdirectory (/DynamicImages/). Here is the contents of that file:

<?xml version="1.0"?>
<configuration>
<system.web>
<customErrors mode="On" defaultRedirect="/GenericErrorPage.aspx">
<error statusCode="404" redirect="/DynamicImages/Generate.ashx" /
>
</customErrors>
</system.web>
</configuration>

If i goto /DynamicImages/a-file-which-does-exist.jpeg, i get the image
returned (because it exists). If i goto: /DynamicImages/a-file-which-
does-NOT-exist.jpeg, i get redirected to /DynamicImages/Generate.ashx?
asperrorpath=/dynamicimages/a-file-which-does-NOT-exist.jpeg.

N.B. This hander then creates the missing image and saves it to disc
so that future requests do not 404.

This all works fine through visual studio.

However, when i run this through IIS on the server, the 404
redirecting isnt working :( I assumed this would be because .jpeg isnt
handled by .NET, so i set up a rule in IIS to pass all .jpeg through
the .NET handler, but it still doesnt work :(

Can anyone suggest why? Whats most annoying is it works on my machine!
grrr

I know i can use an iis custom error redirect to handle these .jpegs,
however this presents several problems to me. firstly i cant get the
path which caused the error (which i need to be able to create the
image, the filename tells me what to create), and secondly it wont
work through visual studio without me coding two different ways of
dealing with the 404, one for debug/dev and one for live, which id
rather not do.

Thanks for any advice,

Andrew

Re: Custom Errors for non .aspx files by trullock

trullock
Wed Sep 03 07:33:24 CDT 2008

On Sep 3, 1:27=A0pm, trull...@googlemail.com wrote:
> Hi,
>
> I have a web application with an additional web.config file in a
> subdirectory (/DynamicImages/). Here is the contents of that file:
>
> <?xml version=3D"1.0"?>
> <configuration>
> =A0 <system.web>
> =A0 =A0 <customErrors mode=3D"On" defaultRedirect=3D"/GenericErrorPage.as=
px">
> =A0 =A0 =A0 <error statusCode=3D"404" redirect=3D"/DynamicImages/Generate=
.ashx" /
>
> =A0 =A0 </customErrors>
> =A0 </system.web>
> </configuration>
>
> If i goto /DynamicImages/a-file-which-does-exist.jpeg, i get the image
> returned (because it exists). If i goto: /DynamicImages/a-file-which-
> does-NOT-exist.jpeg, i get redirected to /DynamicImages/Generate.ashx?
> asperrorpath=3D/dynamicimages/a-file-which-does-NOT-exist.jpeg.
>
> N.B. This hander then creates the missing image and saves it to disc
> so that future requests do not 404.
>
> This all works fine through visual studio.
>
> However, when i run this through IIS on the server, the 404
> redirecting isnt working :( I assumed this would be because .jpeg isnt
> handled by .NET, so i set up a rule in IIS to pass all .jpeg through
> the .NET handler, but it still doesnt work :(
>
> Can anyone suggest why? Whats most annoying is it works on my machine!
> grrr
>
> I know i can use an iis custom error redirect to handle these .jpegs,
> however this presents several problems to me. firstly i cant get the
> path which caused the error (which i need to be able to create the
> image, the filename tells me what to create), and secondly it wont
> work through visual studio without me coding two different ways of
> dealing with the 404, one for debug/dev and one for live, which id
> rather not do.
>
> Thanks for any advice,
>
> Andrew

Solved it with this in the main webconfig:

<httpHandlers>
<add verb=3D"GET,HEAD" path=3D"*.jpeg"
type=3D"System.Web.StaticFileHandler"/>

Andrew