PC Review


Reply
Thread Tools Rate Thread

Custom Errors for non .aspx files

 
 
trullock@googlemail.com
Guest
Posts: n/a
 
      3rd Sep 2008
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
 
Reply With Quote
 
 
 
 
trullock@googlemail.com
Guest
Posts: n/a
 
      3rd Sep 2008
On Sep 3, 1:27*pm, 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="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
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to catch errors in .aspx file AAaron123 Microsoft ASP .NET 6 20th Apr 2009 01:29 PM
404 errors for ASPX PAGES Justin Microsoft ASP .NET 3 19th May 2006 10:52 PM
Anyone Find IIS 404 Errors custom handled by ASPX causes viewstate problem? Jonathan Folland Microsoft ASP .NET 0 1st Apr 2005 05:14 PM
get_aspx_ver.aspx errors ? Brian Henry Microsoft ASP .NET 1 6th Dec 2003 11:23 PM
Specifying all files except Login.aspx and Join.aspx are restricted to authenticated users SamIAm Microsoft ASP .NET 1 4th Dec 2003 02:59 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:00 AM.