Display images in Custom Error Pages

L

Laurie Dvorak

I'm working on converting a website that currently is all static HTML pages
to ASP.NET. Since people may have some of the HTML pages bookmarked, I
want to give them a meaningful error message page and point them to the new
pages. In my web.config file, I put the following:

<customErrors mode="On">
<error statusCode="404" redirect="404NotFound.aspx"/>
</customErrors>

This works fine if I try to request a non-existent file that has a ".aspx"
extension, but it doesn't work if the file has a ".html" extension. So in
IIS on the Custom Errors tab under 404, I put:

Message Type: URL
URL: /MyWeb/404NotFound.aspx

This now works for any file that doesn't have a ".aspx" extension. Now
when I try to go to "http://localhost/MyWeb/BadFile.html" it displays the
error page just fine. The problem comes in when I try to go to a page that
doesn't exist in a sub-directory, for example,
"http://localhost/MyWeb/SubDir/BadFile.html". The error message still
displays, but it can't find any of the images and they just display as red
X's. I always use the ~ in my image URL's (for example, <asp:Image
ImageUrl="~/images/logo.gif">) so I would think it should be able to find
it, but it can't.

Any ideas on what I'm doing wrong?

Thanks,
Laurie
 
L

Laurie Dvorak

Another observation I've made is that the URL in the browser doesn't update.
When I go to http://localhost/MyWeb/SubDir/BadFile.aspx, the URL in the
browser updates to
http://localhost/MyWeb/404NotFound.aspx?aspxerrorpath=/MyWeb/SubDir/BadFile.aspx.
However if I go to http://localhost/MyWeb/SubDir/BadFile.html, the URL in
the address bar is never updated even though the contents of the error page
are displayed (with the images messed up). If I look at the source of the
HTML, the form tag look like:

<form name="form1" method="post"
action="404NotFound.aspx?404;http://localhost/MyWeb/SubDir/BadFile.html"
id="form1">

That makes me think the form needs to be posted or something.

I must be missing something very basic here. Any help would be appreciated.

Thanks,
Laurie
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top