Sitefinity 7.2 - false 404s
Since updating to 7.2 I'm receiving false 404s from Sitefinity, with MVC widgets.
I have an MVC widget at this address:
That widget's controller has an action called "Course" on it, that takes an int as a parameter. If I modify the URL to:
I get a 404 returned. This is obviously incorrect, that URL is perfectly valid. I assume this is to do with this supposed "fix":
feedback.telerik.com/.../137924-invalid-urls-are-resolved-if-you-have-an-mvc-widget-on-the-page
Has anyone else experienced this? Anyone have any ideas?
Try overridding the HandleUnknownAction method in your controller. There's a bit of an explanation here: HandleUnknownError post. From what I have been seeing, actions not called 'Index' will never get the same routing as in a regular MVC application. 'Index' is always called, regardless of the URL. I think Sitefinity is missing the 'course' action and looking for a page with that URL.
I've used the HandleUnkownAction method then used the below code to handle multiple parameters in the URL.
List<
string
> segments = RouteHelper.SplitUrlToPathSegmentStrings( Request.Url.LocalPath,
true
).Skip(1).ToList();
Hi Steve,
Thanks for the help.
From what I have been seeing, actions not called 'Index' will never get the same routing as in a regular MVC application. 'Index' is always called, regardless of the URL. I think Sitefinity is missing the 'course' action and looking for a page with that URL.
This is actually exactly how Sitefinity worked before the upgrade to 7.2. If you check the page now, I've actually rolled back the upgrade and you can see that the controller/action routing is working very well based on the URL supplied. This is how MVC is supposed to work, so I'd be very surprised if Sitefinity's implementation deliberately chose to omit this behaviour.
I'm pretty sure this is a bug that was introduced with this fix:
MVC Support:Invalid URLs are resolved if you have a MVC widget on the page (FP). DISCLAIMER: As a result of this fix Sitefinity is now returning “Error 404”, therefore some of the links to your site might be broken. Note that you might revert the fix by overriding the InitializeRouteParameters method of the ControllerActionInvoker class and placing the RouteHelper.SetUrlParametersResolved(); after the invocation of the base InitializeRouteParameters method.
- www.sitefinity.com/.../sitefinity-7-2-released
It appears as though Sitefinity is incorrectly identifying the URL as "invalid". I think that's where the bug lies - so the 404 is deliberate and working as intended, but the URL being identified as invalid is where the bug lies.
The 7.2 upgrade hosed my SF MVC widget controllers with 404 - I had multiple actions per controller and had been relying on HandleUnknownAction to identify specific actions. I got it working with 7.2 as follows.
1. Create a custom ControllerActionInvoker:
using
Telerik.Sitefinity.Mvc;
using
Telerik.Sitefinity.Web;
namespace
SitefinityWebApp.Mvc
public
class
MvcControllerActionInvoker:ControllerActionInvoker
protected
override
void
InitializeRouteParameters(Telerik.Sitefinity.Mvc.Proxy.MvcProxyBase proxyControl)
base
.InitializeRouteParameters(proxyControl);
// Always mark as resolved (no 404'S)
RouteHelper.SetUrlParametersResolved();
2. Inject the custom ControllerActionInvoker via IOC in global.asax
protected
void
Application_Start(
object
sender, EventArgs e)
Bootstrapper.Initialized += OnBootstrapperInitialized;
protected
static
void
OnBootstrapperInitialized(
object
sender, ExecutedEventArgs e)
switch
(e.CommandName)
case
"Bootstrapped"
:
// override IOC
// "MvcControllerActionInvoker" is the name of my custom
// ControllerActionInvoker, above.
ObjectFactory.Container.RegisterType<IControllerActionInvoker, MvcControllerActionInvoker>(
new
InjectionMember[0]);
break
;
Thank you so much, I just encountered this exact issue and you saved my bacon.