November Happy Hour will be moved to Thursday December 5th.

Where do I define special routes for MVC that will NOT go through EPI?

Vote:
 

I have a need to define an MVC Route that won't go through the Epi pipeline. But, currently there's no place in my project were I see other routes defined.

I am guessing most of it is happening in the Epi classes. I know where they go in a standard MVC 5 project, but my Epi project seems different.

#194355
Jun 19, 2018 13:46
Vote:
 

I've you create an Episerver Initialization module https://world.episerver.com/documentation/developer-guides/CMS/initialization/Creating-an-initialization-module/ you can then add the route to your standard MVC controller in the RouteCollection.

        /// <summary>
        /// Initializes this instance.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <remarks>Gets called as part of the EPiServer Framework initialization sequence. Note that it will be called
        /// only once per AppDomain, unless the method throws an exception. If an exception is thrown, the initialization
        /// method will be called repeadetly for each request reaching the site until the method succeeds.</remarks>
        public void Initialize(InitializationEngine context)
        {
            MapRoutes(RouteTable.Routes);
        }

        /// <summary>
        /// Maps the routes.
        /// </summary>
        /// <param name="routes">The routes.</param>
        private void MapRoutes(RouteCollection routes)
        {
            routes.MapRoute(null, "notify-payment", new { controller = "PaymentNotification", action = "Index" });
        }

This adds a route to my controller inheriting from a standard MVC controller

    public class PaymentNotificationController : Controller
    {
        /// <summary>
        /// Method to handle an external notification POST from a payment provider
        /// </summary>
        /// <returns>An instance of HttpStatusCodeResult</returns>
        [HttpPost]
        [AllowAnonymous]
        [ValidateInput(false)]
        public ActionResult Index()
        {
        }
    }
#194357
Jun 19, 2018 15:05
Vote:
 

An alternative is to override RegisterRoutes In your Global.cs file, then you can control wether your custom route should be inserted before or after the EPiServer routes.

#194359
Jun 19, 2018 15:21
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.