Try our conversational search powered by Generative AI!

Simple routing to get value


Using EpiServer 7 WebForms I want to be able to achieve the following:

Call on a EPiServer page for displaying info on a car. The car itself is not a page in EPiServer, much like the product page in EPiServer Commerce

I want to call the page by appending the car registration number in the url ( and then use that registration number on the page to call a search service with that registration number.

Read some articles about the routing but can't really figure out how to use it this way.

So on the page I would like to have the possibility to use the registration number in function calls like:

var carDetails = GetDetails(carRegNr);

Some pointers on how I would achive this would be rellay nice.

Nov 25, 2013 17:22


Sounds like partial routing could be the way, see e.g. or

The example about Blog routing in the latter post could be useful. In that case the partial router returns the same page, that is if you still want to route to the same page. It uses extension method

to set the partial routed data (in your case it would be the registration number).

You could then in the template get the value using:


Edited, Nov 25, 2013 17:35

This seems the correct way, just can't figure out what exactly to put in the SetCustomRouteData. I have this setup:

The template page CarDetailsPageTemplate.aspx + .cs which inherits from CarDetailsPageBase

public class CarDetailsPageBase : PageBase
        private static PageData _carDetailsPage;

        public static PageData CarDetailsPage
                if (_carDetailsPage == null)
                    _carDetailsPage = DataFactory.Get<PageData>((PageReference)StartPage["CarDetailsPage"]);

                return _carDetailsPage;

        public static string CarRegistrationNumber { get; set; }


The CarDetailsPartialRouter looks like this at the moment:

public class CarDetailsPartialRouter : IPartialRouter<CarDetailsPage, CarDetailsPageTemplate>
        public object RoutePartial(CarDetailsPage content, SegmentContext segmentContext)
            //Expected format is RegNumber/
            var regNumber = segmentContext.GetNextValue(segmentContext.RemainingPath);
            if (!String.IsNullOrEmpty(regNumber.Next))

                return content;


            return null;

        public PartialRouteData GetPartialVirtualPath(CarDetailsPageTemplate content, string language, RouteValueDictionary routeValues, RequestContext requestContext)
            return new PartialRouteData()
                    BasePathRoot = CarDetailsPageBase.CarDetailsPage.PageLink,
                    PartialVirtualPath = String.Format("{0}/", CarDetailsPageBase.CarRegistrationNumber)


What do I put in the SetCustomRouteData?

Edited, Nov 26, 2013 10:43

If registration number is the only thing you need, I guess it would be enough to set a string in the partial router like:

segmentContext.SetCustomRouteData<string>("regnumber", theRegnr);

And then in the template you would read out the routed reg nr as:

string regNr = HttpContext.Current.Request.RequestContext.GetCustomRouteData<string>("regnumber")

Note also that you should consume the segment (update RemainingPath) in the router if you handle the segment, that add the following line to your router:

segmentContext.RemainingPath = regNumber.Remaining

Nov 26, 2013 10:50

Yes got it all working now, so nice to be able to do this. Thanks for the input. Also found this article very helpful:

Escpecially the InitalizationModule setup which I didn't really get from the start.

Nov 26, 2013 14:19
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.