URL Attribute Parameter Shortening
I have a web application that uses various query string parameters to do other things. These query string parameters are additive attributes, meaning that user actions change which ones are provided or even the order of what is provided.
Example URLs:
http://dubdubdub.com/MyPage.aspx?MyParam=100+200+300
http://dubdubdub.com/MyPage.aspx?MyParam=200+300+100
In the example URLs above, both result in the same page render. The page loads dynamically, extracts the attributes and shuffles them off开发者_StackOverflow社区 to another service which uses them. The order is irrelevant.
I would like to find a way to condense the MyParam values into a hashed string of some kind, so that my Urls might be able to look like this...
http://dubdubdub.com/5kjh345i/MyPage.aspx
I've considered simple encryption/decryption, but that has resulted in a larger than ideal string.
I'm currently toying with the idea of an in-memory hash table, pulled in at app startup from a database, but this will require that I populate the database with all possible permutations...not something I want to do.
Other options?
Create an efficient binary representation of your attribute set, then encode that into a URL using base64.
This reduces your problem to one of deciding on an efficient binary representation, which is a data compression problem. Ideas like Huffman encoding or arithmetic encoding could be useful - it really depends on the range of your attribute set.
精彩评论