Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sitefinity 8.1 custom MVC routing not working

After update to V8.1 from V6.1, our MVC custom code not working, it returned 404 (custom code is some APIs read content and commerce data using Sitefinity APIs).

According to documentation "here" , it said that "Bootstrapper.MVC.MapRoute is removed. Call the RouteTable.Routes.MapRoute (System.Web.Mvc)instead." , so I changed my code from

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    Bootstrapper.MVC.MapRoute(
           "ExternalAccess",
           "baseApi/{controller}/{action}/{id}",
           new { controller = "MvcMainApiCntr", action = "Index", id = "" }
           );
}

to

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
        "ExternalAccess",
        "baseApi/{controller}/{action}/{id}",
        new { controller = "MvcMainApiCntr", action = "Index", id = "" }
        );
}

But the routing still not working.

Here is a sample of our MVC classes:

using System;
using System.IO;
using System.Net;
using System.Web.Mvc;
using HtmlAgilityPack;
using Telerik.Sitefinity.Abstractions;

namespace SitefinityWebApp.Mvc.Controllers
{
    public class SharedAssetsController : Controller
    {
        [HttpGet]
        public ViewResult GetScripts()
        {
            var rootUrl = anyfunction();
            return View("Scripts", (object) rootUrl);
        }        
    }
}

And here is how we bind routing in global.ascx:

protected void Application_Start(object sender, EventArgs e)
{
    RouteConfig.RegisterRoutes(RouteTable.Routes);  //the first method in that post
    Bootstrap.BootstrapSitefinity();
}

Any idea how can we resole that?

like image 520
Tarek El-Mallah Avatar asked Jul 20 '15 13:07

Tarek El-Mallah


1 Answers

I got the below advice from Sitefinity Support, I think it's working well now.

Regarding this issue, try to move the route registration in the HttpApplication global class like:

void Bootstrapper_Initialized(object sender, Telerik.Sitefinity.Data.ExecutedEventArgs e)
{
    if (e.CommandName == "RegisterRoutes")
    {
        RegisterRoutes(RouteTable.Routes);
    }
}

And also in the "baseApi" try to avoid using the prefix "ext" as such prefix is used by Sitefinity and might have some issues.

like image 75
Tarek El-Mallah Avatar answered Nov 11 '22 07:11

Tarek El-Mallah