2015-06-19 30 views
3

如何排除由sitecore或glassmapper处理的路由?排除Sitecore MVC中的路由

尝试加载标准的MVC路由(控制器/操作)。我不希望sitecore来处理它。我看到这个错误:

Attempt to retrieve context object of type 'Sitecore.Mvc.Presentation.RenderingContext' from empty stack. 

使用Sitecore的8

+0

你可以发布你用来注册路由的路由代码吗?你是通过管道注入吗? –

回答

2

IgnoreUrlPrefixes设置应对此进行处理。

只需在那里添加路由前缀,Sitecore应该忽略它。

<setting name="IgnoreUrlPrefixes" value="....|/yourcontroller"/> 

这里

http://www.sitecore.net/learn/blogs/technical-blogs/john-west-sitecore-blog/posts/2012/06/four-ways-to-process-mvc-requests-with-the-sitecore-aspnet-cms.aspx

+0

我想我有这个地方。但仍然没有运气。虽然动作类型JsonResult似乎工作正常。只有当我尝试返回View()时,我才看到问题。 – xoail

1

更多信息您可以使用MVC路由属性来管理您的定期航线。为此,您需要在sitecore初始化管道中注入一个小处理器。

public class RegisterMvcAttributeRoutesPipeline 
 
{ 
 
    public void Process(PipelineArgs args) 
 
    { 
 
     RouteTable.Routes.MapMvcAttributeRoutes(); 
 
    } 
 
}

然后你需要注入您的处理器:

<sitecore> 
 
    <pipelines> 
 
     <initialize> 
 
     <processor type="{Your processor type here}" patch:before="processor[@type='Sitecore.Mvc.Pipelines.Loader.InitializeControllerFactory, Sitecore.Mvc']" /> 
 
     </initialize> 
 
    </pipelines> 
 
</sitecore>

现在你就可以使用路由属性:

[RoutePrefix("category")] 
 
    public class CategoryController : Controller 
 
    { 
 
     [HttpGet] 
 
     [Route("get/{id}")] 
 
     public ActionResult Get(string id) 
 
     { 
 
      return Content("MVC url with route attributes"); 
 
     } 
 
    }

干杯,亚历克斯 。