Capture Query String from any Orchard Route / Page

Topics: Customizing Orchard, Troubleshooting
Oct 4, 2012 at 6:21 PM

I thought it best to post my question here. Hopefully someone out there knows a solid solution.

I need to capture a "query string" for every possible route in my Orchard site. For example, (given abc123 is my query string):

  • (grab query string, route to page)
  • (route to page)
  • (grab query string, route to page)
  • (route to page)
  • (grab query string, route to page)
  • (route to page)

How would I go about grabbing that query string (abc123) if it exists and then let Orchard serve up the page based on the route?

I guess what makes it challenging is the dynamic nature of Orchard's routing. Any ideas?

Oct 4, 2012 at 7:15 PM

That's not a query string. A query string would be /about?foo=abc123. In that case, routing would work just fine, and you could have a filter grab that as well.

Oct 4, 2012 at 7:23 PM

Correct. I misspoke - /about/abc123 is a route with an {id}. If I went with the true query string approach as you mentioned, /about?foo=abc123, how would I implement a filter to grab that off. Is there an example in code already? I feel like Orchard.Projections has an example of every scenario possible :-P

Oct 4, 2012 at 7:27 PM

Make a search on "Filter" on the code.

Oct 4, 2012 at 8:20 PM

Thanks. I'll try digging through code. I've only implemented StorageFilters.

If you have any additional guidance or types of Filters to reference, it would be appreciated. 

Oct 8, 2012 at 8:56 PM

@bertrandleroy - I've pored over the code. I see a lot of filters, but nothing that jumps out at me as a way to Filter the URL of my route. If you have a few minutes, can you point me in the right direction?

Or anyone?

Oct 9, 2012 at 6:32 PM

Look at RedirectFilter in Contrib.RewriteRules. That should hit pretty close. It's an optional module from the gallery.

Oct 9, 2012 at 8:28 PM

@bertrandleroy - Thanks! Earlier today things finally clicked and I quickly created a filter, but I was using the IResultFilter interface instead of the IActionFilter. I noticed the filter was getting hit twice per page load. I think this should fix things. I appreciate it.