Technology, Smartphones, Games


An Open source URL shortner ASP.NET C#

ShortUrl-Dotnet is a free and open source URL shortner which you can use if you are having a ASP.NET hosting and a MSSQL or MySql server for data storage.

to implement this

1. Go to the application page

2. Click “Download Now” and save shorturl-dotnet.zip

3. Unzip it

4. Create database and table use Schema_SqlServer.sql

5. Read the “README.txt” and make changes to the Web.Config file

 

There is one issue i noted on this application. This application does not check whether the long url is already shortened or not. So i made some changes to the AddUrlToDatabase function in ShortUrl.Utils.cs inside App_Code as follows

 

public static void AddUrlToDatabase(Container oShortUrl) 
        { 
            string sql = "SELECT * FROM url WHERE real_url = @real_url"; 
            Params p = new Params(); 
            p.Add("@real_url", Clean(oShortUrl.RealUrl)); 
            DataTable dt = SqlServer.Recordset(sql, p); 
            if (dt.Rows.Count <= 0) 
            { 
                sql = "INSERT INTO url (short_url, create_date, created_by, real_url) VALUES (@short_url, @create_date, @created_by, @real_url)"; 
                p = new Params(); 
                p.Add("@short_url", oShortUrl.ShortenedUrl); 
                p.Add("@create_date", oShortUrl.CreateDate); 
                p.Add("@created_by", oShortUrl.CreatedBy); 
                p.Add("@real_url", Clean(oShortUrl.RealUrl)); 
                SqlServer.Execute(sql, p); 
            } 
            else 
            { 
                oShortUrl.ShortenedUrl = dt.Rows[0]["short_url"].ToString(); 
            } 
        }

this application also includes a webservice which you can use from any other website or application.

I made few more simple customizations and you can see a demo site here - http://geekiestprojects.net/url/

This is for demo purpose only, i will be clearing the database. So don't use this (they are not short actually , due to the long domain name :) )