Custom 404 handler works great, except for *.php or *.aspx and etc.
I'll paste my custom 404 handler after this. Basicallly it's working fine, except that when I send urls like mysite.com/blablabla.php, I get the IIS 404 and not my custom 404. I breakpoint and debug on my custom handler, basically it's never called.
I feel this has something todo with IIS configuration (running 8.5) but I don't know what exactly.
If I add <httpErrors existingResponse="PassThrough"/> to my web.config,I instead get an empty response, but still no hit on my handler.
Thanks for the help!
using System.Web;
using umbraco.interfaces;
using Umbraco.Core;
using Umbraco.Core.Logging;
using Umbraco.Web;
using Umbraco.Web.Routing;
namespace BTSPromo.Code
{
public class Umbraco404Handler : INotFoundHandler
{
private int redirectId;
public bool Execute(string url)
{
// Use the url to figure out the culture
var lang = UmbracoContext.Current.ContentCache.GetByRoute(HttpContext.Current.Request.Path.Substring(0, 4));
var site = UmbracoContext.Current.ContentCache.GetByRoute("/");
if (lang == null)
{
int notFoundNodeId = site.AsDynamic().page404; // Unset content picker, cast to int, will be 0
if (notFoundNodeId != 0)
{
redirectId = notFoundNodeId;
return true;
}
else
{
// No specified 404
return false;
}
}
else
{
int notFoundNodeId = lang.AsDynamic().page404; // Unset content picker, cast to int, will be 0
if (notFoundNodeId != 0)
{
redirectId = notFoundNodeId;
return true;
}
else
{
// No specified 404 on language node, try site root
notFoundNodeId = site.AsDynamic().page404; // Unset content picker, cast to int, will be 0
if (notFoundNodeId != 0)
{
redirectId = notFoundNodeId;
return true;
}
else
{
// No specified 404
return false;
}
}
}
return false;
}
public bool CacheUrl
{
get { return false; }
}
public int redirectID
{
get { return redirectId; }
}
}
}
Also, I should mention that the behavior for my local website (through Visual Studio) was different than the production website. I think I got a blank page for my local website, but I got the correct 404 page for the production website.
Custom 404 handler works great, except for *.php or *.aspx and etc.
I'll paste my custom 404 handler after this. Basicallly it's working fine, except that when I send urls like mysite.com/blablabla.php, I get the IIS 404 and not my custom 404. I breakpoint and debug on my custom handler, basically it's never called.
I feel this has something todo with IIS configuration (running 8.5) but I don't know what exactly.
If I add <httpErrors existingResponse="PassThrough"/> to my web.config,I instead get an empty response, but still no hit on my handler.
Thanks for the help!
This thread and the threads it links to may help: http://our.umbraco.org/forum/ourumb-dev-forum/bugs/50332-Custom-404-Only-Works-for-Extensionless-and-ASPX-URLs
In the end, what worked for me was doing this:
I don't think I needed to actually set errorMode to "Custom".
Also, I should mention that the behavior for my local website (through Visual Studio) was different than the production website. I think I got a blank page for my local website, but I got the correct 404 page for the production website.
is working on a reply...