Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.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
Sitecore-在应用程序中添加路由\u开始_Sitecore_Sitecore Mvc - Fatal编程技术网

Sitecore-在应用程序中添加路由\u开始

Sitecore-在应用程序中添加路由\u开始,sitecore,sitecore-mvc,Sitecore,Sitecore Mvc,我正在使用sitecore 7.5,我需要在application_start中添加新路由,以便在ajax调用中使用它,但当我运行应用程序时,sitecore似乎将路由作为内容项处理。请提供任何帮助。以下是为您创建路由的代码。在global.asax.cs中,您将从应用程序启动事件处理程序调用RegisterRoutes: protected void Application_Start() { RouteConfig.RegisterRoutes(RouteTa

我正在使用sitecore 7.5,我需要在application_start中添加新路由,以便在ajax调用中使用它,但当我运行应用程序时,sitecore似乎将路由作为内容项处理。请提供任何帮助。

以下是为您创建路由的代码。在global.asax.cs中,您将从应用程序启动事件处理程序调用RegisterRoutes

    protected void Application_Start()
    {
        RouteConfig.RegisterRoutes(RouteTable.Routes);
    }
在这里,您可以将路线指定为:

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.MapRoute(
             name: "test",
             url: "mvc/Forms/{action}/{id}",
             defaults: new { controller = "Forms", action = "Test", id = UrlParameter.Optional }
           );
    }
在本例中,您将使用/mvc/前缀来处理到指定控制器的路由,因此您将其称为:

/mvc/Forms/Test/{you_may_pass_some_optional_GUID_here}
这将路由到FormsController类操作方法测试(字符串id),但您可以忽略id参数

请注意:请注意,在应用程序中设置路由\u Start并不是最好的方法;更好的做法是在初始化管道时实现映射路由,因为它适合Sitecore体系结构:

public class Initialize
{
    public void Process(PipelineArgs args)
    {
        MapRoutes();
    }

    private void MapRoutes()
    {
        RouteTable.Routes.MapRoute(
                "Forms.Test", 
                "forms/test", 
                new
                {
                    controller = "FormsController",
                    action = "Test"
                },
                new[] { "Forms.Controller.Namespace" });
     }
}
实现的其余部分:另外,我之前在博客中写过一篇关于如何实现对路由的ajax调用的文章,这篇文章将指导您完成其余的实现过程:

更新:请确保您的配置中有一个处理前缀的处理程序,请参见以下内容:

<customHandlers>
    <handler trigger="~/mvc/" handler="sitecore_mvc.ashx" />


我非常感谢您的快速回复,但我的问题没有得到解决,url仍重定向到类似于此的Mostafa,我已更新了我的答案(在底部),以帮助您整理您在上述评论中提到的内容