Page Not Found Handler

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.
1/21/2010 5:46:45 PM
Gravatar
Total Posts 1203
Proud member of the mojoPortal team

Help support mojoPortal!
Add-on modules

Re: Page Not Found Handler

Hey guys, pardon me for butting in here. I'm pretty new to Mojo, and I was just exploring the friendly 404 feature to see how it works and how I can customize it. What I'm finding is that the handler's not working on my dev site. It also doesn't seem to be working on www.mojoportal.com and demo.mojoportal.com. On all three, when I hit an invalid URL I get the generic "Server Error, 404 - File or directory not found. The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable." On my site, the System Log shows this error (seems identical to Joe D's):
 

2010-01-21 15:37:38,942 ERROR mojoPortal.Web.PageNotFoundHttpModule - 10.1.102.199 PageNotFoundHttpModule handled error.
System.Web.HttpException: The file '/bzzzzzt.aspx' does not exist.
at System.Web.UI.Util.CheckVirtualFileExists(VirtualPath virtualPath)
at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile)
at System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean noAssert)
at System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp, Boolean noAssert)
at System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath)
at System.Web.UI.PageHandlerFactory.GetHandler(HttpContext context, String requestType, String virtualPath, String path)
at System.Web.HttpApplication.MaterializeHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
 

I'm running IIS 7 under Windows Server 2008 standard.


Thanks,

Jamie

1/22/2010 8:37:30 AM
Gravatar
Total Posts 18439

Re: Page Not Found Handler

Hi All,

I was able to figure out the cause and find a solution for the PageNotFoundHandler not working on IIS 7. The problem also surfaced on this recent thread. Basically it turns out that this is an IIS 7 specific issue, it worked fine all along on IIS 6 and it works fine on my Win 7 development machine which has IIS 7.5. So until recently when I moved mojoportal.com and demo sites from IIS 6/Win 2003 to IIS7/Win 2008 I was not seeing this issue myself. I really had not noticed the 404 handler not working on this site and demo.mojoportal.com after the initial move until someone pointed it out.

So after some research I found there is a way to change this behavior on IIS 7 using some command line commands, however, I'm not command line guru and was hoping for some easy to change setting from the UI so I kept looking a bit and found this solution in Rick Strahl's blog which involves 1 line of code added to our PageNotFoundHttpModule:

app.Context.Response.TrySkipIisCustomErrors = true;

I did not have a test environment with IIS 7 all setup so I deployed a new build on demo.mojoportal.com to verify this solved the issue and then also redployed a new build here on mojoportal.com to solve it here.

This fix will be in svn trunk by later tonight and will be in the next release.

Best,

Joe

1/22/2010 8:58:20 AM
Gravatar
Total Posts 2239

Re: Page Not Found Handler

Hi Joe,

 

Awesome! I am looking forward to the next release.

I am going to give the command line options a try just for kicks. I am an old command line guy so it will be fun! (yeah that's way nerdy)

Thanks!
Joe D.

1/22/2010 10:10:36 AM
Gravatar
Total Posts 2239

Re: Page Not Found Handler

Hello All,

Okay, so I used this command to allow the PassThrough of the response from the PageNotFoundHandler:

C:\Windows\System32\inetsrv>appcmd.exe set config "websiteName/" -section:system.webServer/httpErrors -existingResponse:PassThrough

 

And it added this to my web.config after the handlers section in the system.webServer section:

<httpErrors existingResponse="PassThrough" />

So, I copied that line to another web.config on a different site and all is well with the PageNotFoundHandler.

HTH,
Joe D.

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

Help support mojoPortal!
Add-on modules

Re: Page Not Found Handler

Thanks, guys! Joe D., that web.config modification was perfect for me, since I have a user demo coming up tomorrow morning and don't want to risk rebuilding from SVN source so soon before that demo.

 

3/9/2010 10:46:12 AM
Gravatar
Total Posts 1203
Proud member of the mojoPortal team

Help support mojoPortal!
Add-on modules

Re: Page Not Found Handler

Okay, I have a new question about this, and I'm not sure if this is a bug or a feature request.

If you navigate to http://demo.mojoportal.com/bogus/default.aspx, you get the friendly 404 page.

However, if you navigate to http://demo.mojoportal.com/bogus, http://demo.mojoportal.com/bogus/, or http://demo.mojoportal.com/bogus/index.html, you receive the generic IIS 404 page.

Is it possible to make the URLs in the second scenario also bring up the friendly 404 page? This is very important to us since our current site is HTML based, and without this capability, when we cut the site over to mojoPortal, all existing bookmarks and previously published URLs will lead to a generic 404 page. Obviously, we'd much prefer to have the friendly 404 page come up instead.

Thanks as always, Joe!

Jamie

3/9/2010 10:54:55 AM
Gravatar
Total Posts 2239

Re: Page Not Found Handler

Hi Jamie,

The reason you are not getting the friendly 404 page when using /bogus or *.html is ASP.NET is not setup to handle all requests to the site, only .NET requests.

You can change this behavior by adding runAllManagedModulesForAllRequests="true" to the Modules section of your web.config. So it will look like this:

<modules runAllManagedModulesForAllRequests="true">

You can find the modules section on or about line 1116 in your web.config.

Please note that this will cause all traffic to go through .NET which may be quite a performance hit for your site.

Also keep in mind that this change is in the web.config and not the user.config so you will have to add this setting to your web.config after each upgrade.

HTH,
Joe D.

3/9/2010 10:56:36 AM
Gravatar
Total Posts 2239

Re: Page Not Found Handler

Hi Jamie,

Scratch that. I shoud've tested before posting, not afterwards. I have this setting on my website but the friendly 404 isn't showing up when I use something like /bogus. I thought it would.

I will keep trying. Maybe I'll figure it out.

Thanks,
Joe D.

3/9/2010 11:07:04 AM
Gravatar
Total Posts 18439

Re: Page Not Found Handler

It is also possible to create a custom 404 page in IIS, the process varies depending on IIS version but a little googling should get you going, this thread may help.

Hope it helps,

Joe

3/9/2010 4:27:51 PM
Gravatar
Total Posts 1203
Proud member of the mojoPortal team

Help support mojoPortal!
Add-on modules

Re: Page Not Found Handler

Hey guys, thanks for the tips. I believe I have this figured out now, thanks to this page. For step 6, I used the option "Execute a URL on this site" and pointed it to /PageNotFound.aspx so mojoPortal would handle the error, and I wouldn't need to worry about custom styling a static page. Now, all 404 requests seem to be going to mojoPortal's friendly page. Yay! cool The change also correctly affects sub-sites.

As a result of this change, the following section was added to Web.config below the <handlers> section "Handlers for IIS 7.0 Integrated mode":

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

Joe, can you include this section in the default Web.config you are distributing with mojoPortal? I think this would be a very worthwhile change, as long as it doesn't interfere with people using versions of IIS other than 7.

Jamie

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