Reputation: 3064
How do I exclude a route from being processed by sitecore or glassmapper?
Trying to load a standard MVC route (controller/action). I do not want sitecore to handle it. I see this error:
Attempt to retrieve context object of type 'Sitecore.Mvc.Presentation.RenderingContext' from empty stack.
Using Sitecore 8.
Upvotes: 3
Views: 2276
Reputation: 11
You can use MVC route Attributes to manage your regular routes. To do that you'll need to inject a little processor in sitecore initialize pipeline.
public class RegisterMvcAttributeRoutesPipeline
{
public void Process(PipelineArgs args)
{
RouteTable.Routes.MapMvcAttributeRoutes();
}
}
And then you need to inject 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>
And now you are ready to use 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.
Upvotes: 1
Reputation: 3216
The IgnoreUrlPrefixes
setting should handle this.
Just add the route prefix in there and Sitecore should ignore it.
<setting name="IgnoreUrlPrefixes" value="....|/yourcontroller"/>
More info here
Upvotes: 2