Posted on 19/04/2017 17:38:54
Hi Peter
This was a tough nut to crack, hence the long waiting time.
In Dynamicweb 8, the entire frontend is runing in a webform called /Default.aspx using url rewriting to map /someurl/somepage to Default.aspx?ID=123. In Dynamicweb 9 the frontend is now a MVC controller with a default route that handles Default.aspx (that is why it still works with that in the URL) - but all /someurl/somepage urls are handled by this routehandler.
So when you register your own routehandlers they reside alongside our Dynamicweb.Frontend.DynamicwebRouteHandler, and we have some logic that determines if we should display a 404 if the route looks wrong. And Dynamicweb thinks that because it does not recognise your route.
So, working around this can be fixed - we will add a fix for Dynamicweb that will solve this issue for future installations. For now you can fix it by adding a notification subscriber to your solution.
In your solution add a reference to Dynamicweb.Extensibility.dll and create a notification subscriber that looks like this:
[Dynamicweb.Extensibility.Notifications.Subscribe(Dynamicweb.Notifications.Standard.Application.AuthenticateRequest)]
public class HandleRouteNotification : Dynamicweb.Extensibility.Notifications.NotificationSubscriber
{
public override void OnNotify(string notification, Dynamicweb.Extensibility.Notifications.NotificationArgs args)
{
Dynamicweb.Notifications.Standard.Application.AuthenticateRequestArgs myargs = (Dynamicweb.Notifications.Standard.Application.AuthenticateRequestArgs)args;
System.Web.Routing.RouteData routeData = System.Web.Routing.RouteTable.Routes.GetRouteData(new System.Web.HttpContextWrapper(myargs.Application.Context));
if (routeData != null && routeData.RouteHandler.ToString() != "Dynamicweb.Frontend.DynamicwebRouteHandler")
{
//throw new System.Exception(routeData.RouteHandler.ToString());
myargs.Handled = true;
}
}
public override int Rank
{
get { return base.Rank - 70; }
}
}
As you can tell, it simply asks Dynamicweb to fuck off if there is any other route handler that knows what to do.
Attached a sample solution with a MVC controller and WEB API controller using attributes and including the above notification subscriber. In IIS the solution is setup using virtual folders to /admin and /files, see dump.
BR Nicolai