Sitefinity 8.1 custom MVC routing not working

After upgrading to V8.1 from V6.1, our user MVC code does not work, it returned 404 (user code is some APIs that read content and commercial data using the Sitefinity API).

According to the documentation here , he said that β€œBootstrapper.MVC.MapRoute has been deleted. Call 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 routing still does not work.

Here is an example 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 this 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 we can change this?

+6
source share
1 answer

I got the following advice from Sitefinity Support, I think it works well now.

Regarding this issue, try moving the route registration to the global HttpApplication class, for example:

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

Also, in "baseApi", try to avoid using the "ext" prefix, since such a prefix is ​​used by Sitefinity and may have some problems.

+5
source

All Articles