.ASPX page hit twice if Custom Error page in IIS

J

jonhyland

Hey all,

I'm writing a .NET application where I want all HTTP errors such as 404
to redirect back to the home page.

Since .NET only handles HTTP errors if the client is requesting a .NET
resource (.ASPX, whatever), I need to go into IIS -> Custom Errors tab
and set my homepage under each HTTP error I want to handle. This
allows my page to be shown if someone requests an .ASP or .HTM page
that doesn't exist.

Simple enough so far? Well when I do this, and execute the home page
normally, it gets processed *twice*. I'm not even requesting a missing
resource.

For example, my main page is Default.aspx. If in IIS I set
Default.aspx as my 404 error page, and then go to
"http://whatever.com/Default.aspx", the page is executed *twice* on the
server. If I remove the setting in IIS the behavior goes away.

A little more information some people might ask: No, the page does not
perform a Server.Transfer or Request.Redirect. The version of IIS is 6
(Windows 2003 Server). .NET Framework is 1.1. And the page consists
of a number of user controls (not sure why this would matter but
another vauge posting mentioned this).

Thanks in advance, and if anyone had more specific questions let me
know.

john
 
B

bjc

Hi jonhyland - You should have a web.config file if you're running a .net
app. Although you don't have to but the web.config file is "run" when your
app is hit / requested. Amongst other stuff you can set an error
file/message application wide via such a file. Search about on web.config on
asp dot sites.
 
H

Hans Kesting

bjc said:
Hi jonhyland - You should have a web.config file if you're running a
.net app. Although you don't have to but the web.config file is "run"
when your app is hit / requested. Amongst other stuff you can set an
error file/message application wide via such a file. Search about on
web.config on asp dot sites.

That is not the solution in this case. As the OP said, a .net error handling
only works if the .net system is called. When somehow a non-.net resource
is requested (.asp, .html, .gif), then asp.net is never called by IIS and
thus is incapable of responding.

As to why that page is executed twice, I don't know. A "solution" might
be not to set that default.aspx as error page, but to reserve a special
page for that (maybe log the error and then redirect to default.aspx)

Hans Kesting
 
J

jonhyland

Thanks Hans, I had thought of trying something similar. I'd like to
not have to rely on a 'second' redirect from say a standard ASP page
though.. unless thats the only option. I might take this one to MS,
see what they have to say.
 
J

jonhyland

Thanks Hans, I had thought of trying something similar. I'd like to
not have to rely on a 'second' redirect from say a standard ASP page
though.. unless thats the only option. I might take this one to MS,
see what they have to say.
 
J

jonhyland

How much u want to bet this will post twice. It's been doing it all
week with Google's new "beta" Groups (which I really don't like, BTW).

Anyways, I figured out the cause of the problem.. it was dumb. There
was an embedded 1x1 pixel "blank.gif" file in the page, I'm assuming
for formatting reasons, and that file was missing from the project.

Since IIS was configured to redirect on any 404 (missing resource)
error my page was being hit twice every time. Thought I'd throw this
one out as I bet a lot of people could run into this unknowingly.
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top