Tar*_*lah 6 c# asp.net-mvc sitefinity asp.net-mvc-5
从V6.1更新到V8.1后,我们的MVC自定义代码无效,它返回404(自定义代码是一些API使用Sitefinity API读取内容和商业数据).
根据文档" 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 = "" }
);
}
Run Code Online (Sandbox Code Playgroud)
至
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"ExternalAccess",
"baseApi/{controller}/{action}/{id}",
new { controller = "MvcMainApiCntr", action = "Index", id = "" }
);
}
Run Code Online (Sandbox Code Playgroud)
但路由仍然无法正常工作.
以下是我们的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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
以下是我们如何绑定路由global.ascx:
protected void Application_Start(object sender, EventArgs e)
{
RouteConfig.RegisterRoutes(RouteTable.Routes); //the first method in that post
Bootstrap.BootstrapSitefinity();
}
Run Code Online (Sandbox Code Playgroud)
知道怎么能解决这个问题?
我从Sitefinity支持得到了以下建议,我认为它现在运行良好.
关于这个问题,尝试在HttpApplication全局类中移动路由注册,如:
void Bootstrapper_Initialized(object sender, Telerik.Sitefinity.Data.ExecutedEventArgs e)
{
if (e.CommandName == "RegisterRoutes")
{
RegisterRoutes(RouteTable.Routes);
}
}
Run Code Online (Sandbox Code Playgroud)
并且在"baseApi"中尽量避免使用前缀"ext",因为Sitefinity使用了这样的前缀,并且可能存在一些问题.
| 归档时间: |
|
| 查看次数: |
1632 次 |
| 最近记录: |