How to redirect the pages not mapped to ASP.net into PageNotFound.aspx

If you have questions about using mojoPortal, you can post them here.

You may want to first review our site administration documentation to see if your question is answered there.

This thread is closed to new posts. You must sign in to post in the forums.
12/19/2009 5:01:11 AM
Gravatar
Total Posts 5

How to redirect the pages not mapped to ASP.net into PageNotFound.aspx

Hi Joe,

PageNotFound works well for aspx pages. But when I attemp to access a non aspx file which is not in the web, like a text file, I got IIS default 404 page instead of PageNotFound.aspx. I remembered that it was working in previous version. Right?

My environment is IIS 6.0, Windows2003, mojoPortal 2.3.3.0

Maybe this is a very easy question, but I didn't get it. Thanks.

6/10/2010 1:30:38 PM
Gravatar
Total Posts 1203
Proud member of the mojoPortal team

Help support mojoPortal!
Add-on modules

Re: How to redirect the pages not mapped to ASP.net into PageNotFound.aspx

I know this is revival of a very old thread, but I have recently struggled with this as well and wanted to post the solution I found. In the IIS configuration for your site, there is a section for error pages. Change the 404 handling from file to URL, and give it a value of /PageNotFound.aspx. This places the following entries into web.config, at the bottom of the system.webServer section.

<httpErrors>
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/PageNotFound.aspx" responseMode="ExecuteURL" />
</httpErrors>

I really think this should be the default setting in the delivered mojoPortal web.Config. With this setting in place, all 404 conditions for the site will be handled and not passed to IIS and given a generic message.

Right now, mojoportal.com gives PageNotFound.aspx for http://www.mojoportal.com/blogs.aspx, but a server generic 404 message for: http://www.mojoportal.com/blogs.aspz, or http://www.mojoportal.com/blogs.html. Ideally, shouldn't these be handled the same way?

6/10/2010 1:49:50 PM
Gravatar
Total Posts 18439

Re: How to redirect the pages not mapped to ASP.net into PageNotFound.aspx

Hi Jamie,

If you look in Web.config you'll see I have the <httpErrors> element in there but commented out with a comment that says:

its commented out below because by default IIS7 has this locked down at a parent config file, probably machine.config

On my machine it causes an error and I think if I make it uncommented by default it will cause more support problems.

I will add the 404 entries that you posted into the commented version though, it is a good tip.

Best,

Joe

6/10/2010 1:57:26 PM
Gravatar
Total Posts 1203
Proud member of the mojoPortal team

Help support mojoPortal!
Add-on modules

Re: How to redirect the pages not mapped to ASP.net into PageNotFound.aspx

Thanks Joe, that's perfect! I'm using Server 2008 and Server 2008 R2, so that's probably why I haven't seen any problems with this setting.

Jamie

You must sign in to post in the forums. This thread is closed to new posts.