xoail
xoail

Reputation: 3064

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.

Upvotes: 3

Views: 2276

Answers (2)

Alexander Kravchuk
Alexander Kravchuk

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

Ian Graham
Ian Graham

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

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

Upvotes: 2

Related Questions