473,388 Members | 1,207 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Custom Errors for non .aspx files

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
Sep 3 '08 #1
1 1473
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
Sep 3 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jon Spivey | last post by:
Hi, I've set up a custom error like this <customErrors mode="On" defaultRedirect="ErrorPage.aspx"> <error statusCode="404" redirect="error404.aspx" /> </customErrors> So requests for...
6
by: John Lau | last post by:
Hi, I am looking at the MS KB Article 306355: HOW TO: Create Custom Error Reporting Pages in ASP.NET by Using Visual C# .NET This article describes how to redirect errors to a custom html...
3
by: Bubu | last post by:
Hello this is robert, I need some suggestion, I have a website, hosted in windows 2003 server,shared hosting. I would like to have a custom 404 error page, for missing files. In the help file of...
10
by: Rigs | last post by:
Hi, I have a textbox with a Custom Validator that utilizes the OnServerValidate method for that textbox. This works fine, however the method only executes when data exists in that textbox after...
6
by: Nick Horrocks | last post by:
I have set up a custom error page for 404 errors. However the HTTP status code returned is 302 followed by 200, this causes search engines not to remove old pages from their index. How can I...
5
by: Richard | last post by:
I have been struggling with this for days. I feel I must be missing something simple, and I will be eternally grateful for any help. I'm using VS.NET 2003 on XP Pro Sp2. I searched and found...
0
by: gilly3 | last post by:
I'm coming across all kinds of frustration implementing custom errors in ASP.NET 1.1. First, 401 - Authorization Failed My application uses Windows Integrated Authentication, and restricts...
2
by: JJ | last post by:
I have seen many examples to set custom error pages as follows: <customErrors mode="RemoteOnly" defaultRedirect="errors/ErrorPage.aspx"> <error statusCode="400" redirect="errors/ErrorPage400.aspx"...
4
by: =?Utf-8?B?QWxm?= | last post by:
Hello all, I am having trouble dealing with ~(tilde) in my .Net 1.1 web application, specially when it comes through the URL. For example, when someone requests the following URL:...
1
by: Joe | last post by:
asp.net 2.0 I recently converted a website project to a WAP. I the process I have moved our composite controls into their own subfolder. I have removed the Register directives from the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.