Solved

Custom 404 .aspx Page Not Working

Posted on 2009-04-13
7
2,144 Views
Last Modified: 2012-05-06
I'm trying to implement a custom 404 error .aspx page (with master page).  I have customErrors turned on (see code).  When I run it locally and go to http://localhost:62534/blah (mode="On"), I get my custom error page.  After I publish to my site, if I go to /blah, I get a "The XML page cannot be displayed" error.  If I go to /blah.aspx, I get my custom error page.  If I got to /blah.htm, I get "The XML page cannot be displayed".  How do I get my custom page to load in these situations?  I'd be happy to redirect "The XML page cannot be displayed" errors to my custom page but need to know how.  Thanks
<customErrors mode="RemoteOnly">  <!-- Tried with "On" as well -->

      <error statusCode="404" redirect="~/CustomErrors/FileNotFound.aspx"/>

 </customErrors>

Open in new window

0
Comment
Question by:fprickett
  • 4
  • 2
7 Comments
 
LVL 8

Expert Comment

by:ppittle
Comment Utility
fprickett,

You need to configure IIS Custom Errors for the Site/Virtual Directory.  See the attached screen shot.
deletemeIIS.JPG
0
 
LVL 8

Expert Comment

by:ppittle
Comment Utility
What's happening in your situation is you have .NET configured to handled 404 errors.  However, when a user requests a resource from your web server, IIS initially recieves the request.  It makes a decision on who should handle the request.  For static content (ie a directory listing such as /blah or a static page, /blah.html) it handles the request internally; meaning ASP.NET is never called.  In that situation, if IIS needs to return a status code 404, it'll first check the Custom Errors section for the Virtual Directory or Site, and it will return what ever is listed in that section.  However, in this case ASP.NET is never initialized; the request is never forwarded to the ASP.NET worker proces (aspnet_wp.exe) so you're web.config is never loaded, and ASP.NET doesn't return the error page specified in your web.config.  

When IIS receives a request for an ASP.NET resource, ie an aspx page, the request is forwarded to the ASP.NET worker process (aspnet_wp.exe), which spawns an instance of the .NET CLR and begins processing the request.  In the event that the resource doesn't exist, then ASP.NET checks the web.config to see if the customErrors tag is defined, and returns accordingly.

Thus, when you publish your site, it is imperitive that you configure BOTH asp.net and IIS CustomErrors.

PJ
0
 

Author Comment

by:fprickett
Comment Utility
Sorry, I meant to mention that.  I did configure IIS website (IIS -> Default Web Site -> Properties ->Custom Errors -> 404, 404;2, 404;3 -> File = physicalpathtoroot\CustomErrors\FileNotFound.aspx) to handle custom errors.  It even tries to read the FileNotFound.aspx as evidenced in the details of the "The XML page cannot be displayed" error:

"A name was started with an invalid character. Error processing resource 'http://xxx.xxx.xxx.xxx/Blah.htm'. Line 1, Position..."

"<%@ Page Language="C#" MasterPageFile="~/master.Master" AutoEventWireup="true" CodeBehind="FileNotFound.aspx.cs" Inher..."


0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 8

Accepted Solution

by:
ppittle earned 500 total points
Comment Utility
fprickett:,

In IIS Custom Errors page, when you set the page, there is a drop down to set File or URL.  When you set File, IIS returns the page as markup.  This setting will return your aspx page as if it was an HTML page.  When it gets to your browser, your browser freaks out because it doesn't understand the asp.net tags.

Instead set the drop down to URL.  This will tell IIS to send a redirect to the client to the client requests the Error Page.  That way IIS will have ASP.NET rendering the aspx page before sending it to the client.
0
 
LVL 15

Expert Comment

by:spprivate
Comment Utility
Dont know if you did this part.In the website properties ASP.Net tab click edit configuration and then under customerror tab set it to ON and set the page name.
Check the document
customerror.doc
0
 

Author Closing Comment

by:fprickett
Comment Utility
Thanks a lot ppittle.  Using the Absolute URL /CustomErrors/FileNotFound.aspx worked great.  Needed to parse out the RawURL (Request.RawUrl) in the Page_Load to get the requested page (couldn't use Request.QueryString["aspxerrorpath"]) but it's working great.  
0
 
LVL 8

Expert Comment

by:ppittle
Comment Utility
I'm glad that worked for you.  Having to parse out the Request.RawUrl or using Request.RefererURL is a pain, but that's the IIS architecture for you.  Hopefully they fixed it in IIS 7.0.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A Change in PHP Behavior with Session Write Short Circuit (http://php.net/manual/en/book.session.php#116217) (Winter 2014)** With the release of PHP 5.6 the session handler changed in a way that many think should be considered a bug.  See the note …
Foolproof security solutions has become one of the key necessities of every e-commerce or Internet banking website. If you too own an online shopping site then its vital for you to equip your web portal with customer security features that can allow…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now