Custom Errors for non .aspx files

  • Thread starter Thread starter trullock
  • Start date Start date
T

trullock

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>
</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
 
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

Solved it with this in the main webconfig:

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

Andrew
 
Back
Top