using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using umbraco.interfaces;
using System.Configuration;
namespace UmbracoUS1.Handler
{
public class URLNotFound: INotFoundHandler
{
private int redirectId;
private string[] domains
{
get
{
try
{
return ConfigurationManager.AppSettings["404Domains"].Split(';');
}
catch
{
return null;
}
}
}
bool doReturn = false;
public bool Execute(string url)
{
var server = HttpContext.Current.Request.ServerVariables["SERVER_NAME"].ToLower();
foreach (string domain in domains)
{
if (domain.Contains(server))
{
redirectId = Convert.ToInt32(domain.Split(',')[1]);
doReturn = true;
break;
}
}
return doReturn;
}
public bool CacheUrl { get { return false; } }
public int redirectID { get { return redirectId; } }
}
}
The code works fine in development (VS) and my local deployment, but when I put this code into production the 404 is not caught by the handler.
My local deployment that is working is using the full version of IIS 7 and not express. I do not see anything in the trace logs.
Has anyone experience the same issue? The only thing that is different from dev to production is the 404Domains key in the web config.
I have tested the foreach logic in my master templates and the server value is being matched with the domain value coming from the Web.Config appSetting.
This allowed me to just redirect any html/htm page to a page with the same .aspx file name. Custom 404 then picks it update if its not found. Great side effect is that some pages on the new site have the same file name but with .aspx, so the get served.
Custom 404 handler working locally but not in production
So i followed the Umbraco guide to making a custom 404 handler as I run multiple domains on my Umbraco instance.
Web.Config Entries (Dev and Production):
404handlers.config:
404handler.cs:
The code works fine in development (VS) and my local deployment, but when I put this code into production the 404 is not caught by the handler.
My local deployment that is working is using the full version of IIS 7 and not express. I do not see anything in the trace logs.
Has anyone experience the same issue? The only thing that is different from dev to production is the 404Domains key in the web config.
I have tested the foreach logic in my master templates and the server value is being matched with the domain value coming from the Web.Config appSetting.
Is there an IIS setting I am missing?
Slowly pulling my hair out!
Many thanks
Phillip
So the following added to Web.Config will handle the .aspx pages but not static pages
Any idea how to handle static files?
Answering my own questions again!
I did a little more research and added the following rules to the UrlRewriting config
This allowed me to just redirect any html/htm page to a page with the same .aspx file name. Custom 404 then picks it update if its not found. Great side effect is that some pages on the new site have the same file name but with .aspx, so the get served.
is working on a reply...