Exclude routes in Sitecore MVC
How to exclude route processing by sitecore or glassmapper?
Trying to load the standard MVC route (controller / action). I don't want sitecore to handle this. I see this error:
Attempt to retrieve context object of type 'Sitecore.Mvc.Presentation.RenderingContext' from empty stack.
Using Sitecore 8.
+3
source to share
2 answers
You can use MVC route attributes to control normal routes. To do this, you will need to insert a small processor into the sitecore initialize pipeline.
public class RegisterMvcAttributeRoutesPipeline
{
public void Process(PipelineArgs args)
{
RouteTable.Routes.MapMvcAttributeRoutes();
}
}
And then you need to enter your processor:
<sitecore>
<pipelines>
<initialize>
<processor type="{Your processor type here}" patch:before="processor[@type='Sitecore.Mvc.Pipelines.Loader.InitializeControllerFactory, Sitecore.Mvc']" />
</initialize>
</pipelines>
</sitecore>
You are now ready to use the route attributes:
[RoutePrefix("category")]
public class CategoryController : Controller
{
[HttpGet]
[Route("get/{id}")]
public ActionResult Get(string id)
{
return Content("MVC url with route attributes");
}
}
Cheers, Alex.
+1
source to share