Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Sitefinity 8.1自定义MVC路由不工作_C#_Asp.net Mvc_Asp.net Mvc 5_Sitefinity - Fatal编程技术网

C# Sitefinity 8.1自定义MVC路由不工作

C# Sitefinity 8.1自定义MVC路由不工作,c#,asp.net-mvc,asp.net-mvc-5,sitefinity,C#,Asp.net Mvc,Asp.net Mvc 5,Sitefinity,从V6.1更新到V8.1后,我们的MVC自定义代码不起作用,它返回404(自定义代码是一些使用SiteFinityAPI读取内容和商业数据的API) 根据文档“”,它说“Bootstrapper.MVC.MapRoute被删除。改为调用RouteTable.Routes.MapRoute(System.Web.MVC)”,因此我将代码从 public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRou

从V6.1更新到V8.1后,我们的MVC自定义代码不起作用,它返回404(自定义代码是一些使用SiteFinityAPI读取内容和商业数据的API)

根据文档“”,它说“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 = "" }
           );
}

但是路由仍然不起作用

以下是我们的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();
}

知道我们如何解决这个问题吗?

我从Sitefinity支持部门得到了以下建议,我认为它现在运行良好

关于此问题,请尝试在
HttpApplication
全局类中移动路由注册,如:

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

此外,在“baseApi”中,尽量避免使用前缀“ext”,因为Sitefinity使用了该前缀,并且可能存在一些问题。

您能否解释一下可能会导致哪些问题:“在“baseApi”中,尽量避免使用前缀“ext”,因为Sitefinity使用了该前缀,并且可能存在一些问题。”?这与您的问题有什么关系?我们从Global.asax.cs“Application_Start()”中称为“RegisterRoutes”的问题。但是它应该被移动到“Bootstrapper.Initialized”=>的事件处理程序中,在我们的例子中是“Bootstrapper.Initialized+=OnSitefinityAppInitialized”,除了它应该只在命令名如“e.CommandName==”RegisterRoutes“”时执行。事实上,我不知道确切的原因,但这是Sitefinity支持团队的建议,该解决方案解决了上述问题/现在我的所有API和MVC调用在Sitefinity v8.1中再次正常工作。关于前缀“ext”,实际上支持团队建议更改,但是我没有改变它,它对我很好。我理解你关于处理引导程序事件的回答。要注册WebApi路由,您必须做同样的事情(您也可以使用
(e.CommandName==“Bootstrapped”)
FWIW)。我只是觉得最后一句关于路由键“前缀”的话与问题无关。唯一可能发生的问题是,如果Telerik决定在将来的版本中添加具有相同密钥的路由,这将是一个潜在问题,无论您选择的密钥是什么。
void Bootstrapper_Initialized(object sender, Telerik.Sitefinity.Data.ExecutedEventArgs e)
{
    if (e.CommandName == "RegisterRoutes")
    {
        RegisterRoutes(RouteTable.Routes);
    }
}