Adding UrlRewriting rules programmatically on application start
Hi,
Has anyone succeeded in (or even tried) adding/inserting UrlRewriting rules programmatically during umbraco startup (an ApplicationBase-derived class constructor)? I'm out of ideas here...
My rules work perfectly when added to UrlRewriting.config, but when I try to add them from my app class, nothing happens. And yes, I'm doing some logging to my own database and my code does get called, produces the correct strings and so on, and there are no exceptions. It... just doesn't work...
I've read the UrlRewriting documentation fifty times and tried every conceivable (to my mind) reasonable combination of options and parameters (just in case something got lost in translation from German).
After thinking that umbraco perhaps got higher in the list than I did, I created a dummy rule in the .config file and told UrlRewriting to insert my dynamic rules before the dummy rule. Nope. Just doesn't "take".
Any clues?
Why do I need it? Becase I have a customer with a multilingual (around ten languages, still counting) site, and the word "products" is NOT the same in all languages - I need to identify requests to a product database and convert the trailing parts of the path (which is something like "/en/products/thiscategory/thatsubcategory/thisproduct/" into a query string. And I would like it for the customer to be able to add languages and/or correct translations without involving me...
I would VERY much like to do that programmatically. I can catch events and notice when the customer adds countries or corrects a misspelling of a translation of "products", and track them in MY database (which is actually prepared to talk to me during app startup). So far, all is well. But as for doing someting about it - inserting the rules - not so much...
I don't have the exact answer you're looking for but prehaps you could do this a different way? I'm assuming that requests to the product without the correct spelling would generate an 404? You could catch the 404 and add some logic that looks at a list of words/nodes added by your client and then redirect or handle the request in your code?
Adding UrlRewriting rules programmatically on application start
Hi,
Has anyone succeeded in (or even tried) adding/inserting UrlRewriting rules programmatically during umbraco startup (an ApplicationBase-derived class constructor)? I'm out of ideas here...
My rules work perfectly when added to UrlRewriting.config, but when I try to add them from my app class, nothing happens. And yes, I'm doing some logging to my own database and my code does get called, produces the correct strings and so on, and there are no exceptions. It... just doesn't work...
I've read the UrlRewriting documentation fifty times and tried every conceivable (to my mind) reasonable combination of options and parameters (just in case something got lost in translation from German).
After thinking that umbraco perhaps got higher in the list than I did, I created a dummy rule in the .config file and told UrlRewriting to insert my dynamic rules before the dummy rule. Nope. Just doesn't "take".
Any clues?
Why do I need it? Becase I have a customer with a multilingual (around ten languages, still counting) site, and the word "products" is NOT the same in all languages - I need to identify requests to a product database and convert the trailing parts of the path (which is something like "/en/products/thiscategory/thatsubcategory/thisproduct/" into a query string. And I would like it for the customer to be able to add languages and/or correct translations without involving me...
I would VERY much like to do that programmatically. I can catch events and notice when the customer adds countries or corrects a misspelling of a translation of "products", and track them in MY database (which is actually prepared to talk to me during app startup). So far, all is well. But as for doing someting about it - inserting the rules - not so much...
*sigh*
Hey Peter,
I don't have the exact answer you're looking for but prehaps you could do this a different way? I'm assuming that requests to the product without the correct spelling would generate an 404? You could catch the 404 and add some logic that looks at a list of words/nodes added by your client and then redirect or handle the request in your code?
Regards
Rich
is working on a reply...