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


The parameter IgnoreUrlPrefixes

should handle this.

Just add the route prefix there and Sitecore should ignore it.

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

      



More details 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

+2


source


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();
   }
}
      

Run codeHide result


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>
      

Run codeHide result


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");
        }
    }
      

Run codeHide result


Cheers, Alex.

+1


source







All Articles