6
從V6.1更新到V8.1後,我們的MVC自定義代碼無法工作,它返回404(自定義代碼是一些API使用Sitefinity API讀取內容和商業數據)。Sitefinity 8.1自定義MVC路由不起作用
根據文檔「here」,它表示「Bootstrapper.MVC.MapRoute被刪除,而是調用RouteTable.Routes.MapRoute(System.Web.Mvc)」。 ,所以我改變了我的代碼
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 = "" }
);
}
到
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"ExternalAccess",
"baseApi/{controller}/{action}/{id}",
new { controller = "MvcMainApiCntr", action = "Index", id = "" }
);
}
但路由仍然沒有工作。
這裏是我們的MVC類的一個示例:
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);
}
}
}
這裏是我們如何綁定在global.ascx
路由:
protected void Application_Start(object sender, EventArgs e)
{
RouteConfig.RegisterRoutes(RouteTable.Routes); //the first method in that post
Bootstrap.BootstrapSitefinity();
}
任何想法,我們如何能換鞋底嗎?
你能解釋一下可能導致什麼問題:「並且在'baseApi'中,儘量避免使用前綴'ext',因爲這樣的前綴被Sitefinity使用,並且可能有一些問題。」?這與你的問題有什麼關係? –
我們稱之爲Global.asax.cs「Application_Start()」中的「RegisterRoutes」的問題。但它應該被移動到「Bootstrapper.Initialized」==>的事件處理程序中,在我們的例子「Bootstrapper.Initialized + = OnSitefinityAppInitialized」中,除了它應該僅在命令名稱如「e.CommandName ==」RegisterRoutes「 」。 其實我不知道確切的原因,但這是Sitefinity支持團隊的建議,該解決方案解決了上述問題/現在我所有的API和MVC調用在sitefinity v8.1中都能很好地工作。 –
關於前綴'ext',實際上它是由支持團隊推薦改變的,但我沒有改變它,它對我很好。 –