Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

Can you setup ignore routing in EPi?

Vote:
 

I have an existing website - a WebForms project - that hooks into EPiServer. Call it www.example.com.
EPi is on control of routing, though I am unsure how it manages routing (newbie).
I would like to build out a new route - call it www.example.com/app - using a new WebForms page/code-behind and (important!) will not result in 404 from EPi.

In fact, I would like EPi to ignore www.example.com/app and all of its child routes completely, allowing me to build the base page for a new SPA within the existing website. Allowing me to have

  • www.example.com/app
  • www.example.com/app/cool-thing-1
  • www.example.com/app/cool-thing-1/12345
  • www.example.com/app/cool-thing-2
  • etc

Basis for the request is to create something akin to an index.html or index.aspx in that ignored location within the folder structure of the existing WebForms project, and load a SinglePageApplication within it.

I have attempted this, but EPi results in 404s for the SPA's routed views. Other words, www.example.com/app may load in the browser, but all routed templates result in 404s.

Is there a recommended approach for handling this problem? Was thinking of establishing ignore routes, but with EPi in control of routing, I wasn't sure where to start. Any guidance is appreciated.

#150977
Jul 05, 2016 18:46
Vote:
 

First register a route for your webform pages. You can do this in global.asax by overriding the RegisterRoutes method:

public class EPiServerApplication : EPiServer.Global
    {
       
        protected override void RegisterRoutes(System.Web.Routing.RouteCollection routes)
        {
            base.RegisterRoutes(routes);
            routes.MapPageRoute(
                "SPARoute",
                "App/{firstLevel}/{secondLevel}",
                "~/Views/SPAStartPage.aspx", false, new RouteValueDictionary() { { "firstLevel", string.Empty },{"secondLevel", string.Empty } }
            );
        }

I created a new route that match basically everything below /App and routes this to the webform page at /Views/SPAStartPage.aspx. 

At this page you can now get the route values like:

<form id="form1" runat="server">
    <div>
        Hello SPA world!<br/>
        Querystring parameters:<br/>
        First Level: <%=RouteData.Values["firstLevel"]%><br/>
        Second Level: <%=RouteData.Values["secondLevel"]%><br/>
        
    </div>
</form>

Hope that gets you started on you SPA :)

Happy coding!

#150979
Jul 05, 2016 20:19
* 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.