U4-1441 - refactor (fix) legacy NotFoundHandler support
This commit is contained in:
@@ -3,14 +3,24 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using System.Xml;
|
||||
using System.Reflection;
|
||||
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Logging;
|
||||
|
||||
namespace Umbraco.Web.Routing
|
||||
{
|
||||
// provides internal access to legacy url -- should get rid of it eventually
|
||||
internal static class NotFoundHandlerHelper
|
||||
internal class NotFoundHandlerHelper
|
||||
{
|
||||
const string ContextKey = "Umbraco.Web.Routing.NotFoundHandlerHelper.Url";
|
||||
|
||||
static NotFoundHandlerHelper()
|
||||
{
|
||||
InitializeNotFoundHandlers();
|
||||
}
|
||||
|
||||
public static string GetLegacyUrlForNotFoundHandlers()
|
||||
{
|
||||
// that's not backward-compatible because when requesting "/foo.aspx"
|
||||
@@ -70,5 +80,60 @@ namespace Umbraco.Web.Routing
|
||||
httpContext.Items[ContextKey] = tmp;
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
|
||||
static IEnumerable<Type> _customHandlerTypes = null;
|
||||
|
||||
static void InitializeNotFoundHandlers()
|
||||
{
|
||||
// initialize handlers
|
||||
// create the definition cache
|
||||
|
||||
LogHelper.Debug<NotFoundHandlerHelper>("Registering custom handlers.");
|
||||
|
||||
var customHandlerTypes = new List<Type>();
|
||||
|
||||
var customHandlers = new XmlDocument();
|
||||
customHandlers.Load(Umbraco.Core.IO.IOHelper.MapPath(Umbraco.Core.IO.SystemFiles.NotFoundhandlersConfig));
|
||||
|
||||
foreach (XmlNode n in customHandlers.DocumentElement.SelectNodes("notFound"))
|
||||
{
|
||||
var assemblyName = n.Attributes.GetNamedItem("assembly").Value;
|
||||
var typeName = n.Attributes.GetNamedItem("type").Value;
|
||||
|
||||
string ns = assemblyName;
|
||||
var nsAttr = n.Attributes.GetNamedItem("namespace");
|
||||
if (nsAttr != null && !string.IsNullOrWhiteSpace(nsAttr.Value))
|
||||
ns = nsAttr.Value;
|
||||
|
||||
LogHelper.Debug<NotFoundHandlerHelper>("Registering '{0}.{1},{2}'.", () => ns, () => typeName, () => assemblyName);
|
||||
|
||||
Type type = null;
|
||||
try
|
||||
{
|
||||
//TODO: This isn't a good way to load the assembly, its already in the Domain so we should be getting the type
|
||||
// this loads the assembly into the wrong assembly load context!!
|
||||
|
||||
var assembly = Assembly.LoadFrom(Umbraco.Core.IO.IOHelper.MapPath(Umbraco.Core.IO.SystemDirectories.Bin + "/" + assemblyName + ".dll"));
|
||||
type = assembly.GetType(ns + "." + typeName);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogHelper.Error<NotFoundHandlerHelper>("Error registering handler, ignoring.", e);
|
||||
}
|
||||
|
||||
if (type != null)
|
||||
customHandlerTypes.Add(type);
|
||||
}
|
||||
|
||||
_customHandlerTypes = customHandlerTypes;
|
||||
}
|
||||
|
||||
public static IEnumerable<Type> CustomHandlerTypes
|
||||
{
|
||||
get
|
||||
{
|
||||
return _customHandlerTypes;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user