Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude routes in Sitecore MVC

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.

like image 967
xoail Avatar asked Nov 29 '25 11:11

xoail


2 Answers

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

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

like image 53
Ian Graham Avatar answered Dec 01 '25 05:12

Ian Graham


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.

like image 24
Alexander Kravchuk Avatar answered Dec 01 '25 04:12

Alexander Kravchuk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!