Run hashids server-side

322 Views Asked by At

I'm trying to use hashids in javascript and ASP but I need it to run on server-side as some check with DB need to occur before loading the page. The examples/documentation on their site don't cover that. Can anyone give an example on the library is added to my asp and how to call encode() and decode(). Keep getting error 500 and I have to say I have never tried to run server-side an external library like this.

BTW, a tip to help other people, if you want to have something similar to tinyurl (like http://[domain]/[optional_subdirectory]/[hashid]) and only a single file on IIS to do the decoding, I setup a custom 404 page that catches all urls within the server and variable QUERY_STRING holds that hash for decoding and further processing ;)

var hash = String("<%=Request.ServerVariables('QUERY_STRING')%>").split("/").pop()
1

There are 1 best solutions below

3
On

If you want to run Hashids server side and use ASP(.NET?) there is a .NET version of the library.

http://hashids.org/net/

With more examples here https://github.com/ullmark/hashids.net

Edit: I also encourage people to not follow your tip and use a 404 page as a catch all route. ASP.NET has multiple ways of setting up routing. Again, if you were talking about ASP Classic then... I'm sorry ;-)