Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
AI OnAI Off
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
I have a page type with a web form template that displays different integrated data based on two querystring int parameters.
The int's have a registry of URL friendly names.
I've looked at Joel's http://joelabrahamsson.com/custom-routing-for-episerver-content/ and created a RoutePartial method to be able to have a URL such as /createinquiry/mycategory-in-myregion/ instead of /createinquiry/?categoryid=666®ionid=888.
public object RoutePartial(CreateInquiryPage content, SegmentContext segmentContext) { if (!content.ContentLink.CompareToIgnoreWorkID(Site.Settings.Instance.CreateInquiryPageLink)) { return null; } var nextSegment = segmentContext.GetNextValue(segmentContext.RemainingPath); var urlSegment = nextSegment.Next; if (string.IsNullOrEmpty(urlSegment)) { return null; } Log.DebugFormat("CreateInquiryRouter urlSegment {0}", urlSegment); segmentContext.RemainingPath = nextSegment.Remaining; segmentContext.RoutedContentLink = Site.Settings.Instance.CreateInquiryPageLink; segmentContext.SetCustomRouteData("categoryid", 666); segmentContext.SetCustomRouteData("regionid", 888); return null; }
urlSegment above contains "testparam" extracted from the full URL /createinquiry/testparam/ which is exactly what I want. I will of course later resolve the correct ID's but for now I just use segmentContext.SetCustomRouteData() to attach hard coded int's to the request.
I don't need GetPartialVirtualPath() so I just return an empty object. Maybe it's better to return a NotImplementedException()?
In the web form I fetch the values using Request.RequestContext.GetCustomRouteData<int>("categoryid").
Is this a good approach and/or what other options do I have?
Is it possible to rewrite the request in RoutePartial so that my web form works just using Reqeust.QueryString["categoryid"] both routed and unrouted?