Click here to Skip to main content
15,880,972 members
Articles / Web Development / ASP.NET
Article

Zeta Tiny Url Web Service

Rate me:
Please Sign up or sign in to vote.
3.95/5 (14 votes)
7 Dec 2006CPOL3 min read 90.7K   305   16   2
Introducing a web service to generate short URLs from long URLs

Image 1

Introduction

This article presents you a programmatic way to generate a short URL from a long URL. This is especially useful when you want to send e-mail messages (or even instant messages) to others and want to avoid the clients to break long URLs into multiple lines, thus rending them unclickable.

E.g. a long URL could be

http://www.de.map24.com/source/print/v3.0.1/
cnt_route_print_options.php?map24_sid=
d59b9f7b08f2de1e6b996cdc87972d41_MTAuMzkuOS40&map=1

And a short URL generated from this long URL could be

http://tinyurl.com/ynh3hb

To read a more detailed description, please see www.tinyurl.com.

The basics of services like TinyURL.com is that they keep a simple dictionary (also called "hash table" or "associative array") that stores the short URL as the key and the long URL as the value of an entry in the dictionary. When you enter the short URL into your web browser, a lookup is done and a redirect is executed to the long URL.

For instant testing the code of this article, visit www.zeta-sw.com/tinyurl.

What the web service does

The web service I've written is simply a wrapper to TinyURL.com. It has one simple method to call:

string MakeTinyUrl( string longUrl );

You pass a long URL and get a short URL. That's it.

Behind the scenes

The download as of now contains not one backend, but two:

1.) Interface to TinyURL.com

This was my first implementation. Since TinyURL.com does not offer a programatic way to access the service, I basically do a HTTP post to the TinyURL.com site and then screen-scrapping the results with some Regular Expressions.

That of course means that I must adjust the code whenever the TinyURL.com guys change their output HTML.

2.) Interface to SLink.in

Fortunately, this week, my co-worker Rainer Bendig registered the domain slink.in (Since you don't know Rainer, to sum up, he is the guy that constantly buys and sells domain names - in our office he is already infamous for registering more domains per day than he answers customer support calls :-).

At this domain, Rainer provides the same functionality than TinyURL.com but also accessible as a web service. I enhanced my application so that you are now able to switch to SLink.in by simply changing a configuration value in the Web.config file.

Effectively you can now use my web service to access another web service, but with a consistent interface. If I add more alternatives in the future, the web service that is presented to the consuming code still stays constant, because the calles to the different services happen in the backend.

Points of Interest

Special topics covered in the code include:

Enjoy the web service! And as always, please post your comments, questions, bug reports or worships in the comment section below. I really do appreciate your feedback!

History

  • 2006-12-07: First version created.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Chief Technology Officer Zeta Software GmbH
Germany Germany
Uwe does programming since 1989 with experiences in Assembler, C++, MFC and lots of web- and database stuff and now uses ASP.NET and C# extensively, too. He has also teached programming to students at the local university.

➡️ Give me a tip 🙂

In his free time, he does climbing, running and mountain biking. In 2012 he became a father of a cute boy and in 2014 of an awesome girl.

Some cool, free software from us:

Windows 10 Ereignisanzeige  
German Developer Community  
Free Test Management Software - Intuitive, competitive, Test Plans.  
Homepage erstellen - Intuitive, very easy to use.  
Offline-Homepage-Baukasten

Comments and Discussions

 
GeneralMy vote of 1 Pin
PeaceTiger10-Jun-09 23:21
PeaceTiger10-Jun-09 23:21 
GeneralSorry but ..... Pin
mbaocha6-May-09 17:31
mbaocha6-May-09 17:31 
Sorry but i cant make much sense out of these. Are you saying that the long and the short url are thesame?



Regards

______________________________________________________________________
Cheap Affordable Web Hosting | Windows Linux PHP ASPX MYSQL Website Hosting | Best Web Design & Development Company

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.