Partial Route instead of querystring in Web Forms project


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 and created a RoutePartial method to be able to have a URL such as /createinquiry/mycategory-in-myregion/ instead of /createinquiry/?categoryid=666&regionid=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?


Aug 12, 2013 10:24
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.