A simple URL shortening service using .NET, Azure and ServiceStack.
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Durwella.UrlShortening.Tests
Durwella.UrlShortening.Web
Durwella.UrlShortening
.gitignore
LICENSE
README.md
UrlShortening.sln
azuredeploy.json
nuget.config

README.md

URL Shortening

A simple URL shortening service using .NET and Azure.

Deploy to Azure GitHub license Build status

Deployment

You can deploy to Azure using the above button. Prior to deployment you should have an existing Azure Storage Account. Copy the connection string to the clipboard; you will be prompted for it during deployment in a field labeled AzureStorageConnectionString.

Once deployed you can add or modify the connection string for AzureStorage.

  1. Click Manage when deployment is finished (or browse to the web app on the Azure Portal
  2. Click Settings
  3. Select Application settings
  4. Click Show Connection Strings
  5. Add a new Custom connection string named AzureStorage and paste the connection string to an Azure Storage Account

If you do not provide the Azure Storage connection string an in-memory URL Alias repository will be used. In that case short URLs will break when the web app is restarted.

Architecture

UrlShortener contains the core logic. There are interfaces you can use to customize the specific mechanics:

  • IHashScheme - Used to generate the short URL. Should generate an appropriate short "hash" from a long string. A default implementation is provided which is based on Base64 encoding of SHA1. Implementations must also provide a way to iteratetively generate new hashes from the same input in the case of a hash collision.
  • IAliasRepository - Dictionary-like persistence of "alias" or "hash" of one string (the key) to another (the value). Used to save mapping between short and long URLs. The default uses Azure Table storage. The fallback uses an in-memory Dictionary.
  • IUrlUnwrapper - Responsible for resolving a direct URL to a resource. For example the provided URL might already be a 'short URL', which could lead to multiple redirects or a redirect loop. The default uses WebClient.

Contributing

  • Natural enhancements to this project would be:
  • Core logic in the Durwella.UrlShortening project must be unit tested.
  • Unit tests should be written using 3 paragaphs corresponding to Arrange, Act and Assert
  • Build must remain clean (no warnings, tests passing)
  • Code Analysis issues should not be introduced
  • Must be deployable to Azure using AzureDeploy.net

References

URL Shortening: Hashes In Practice
Nice article by Jeff Atwood. Historical yet relevant.

Using Custom Azure Resource Management Templates
Helpful for understanding what is going on with the azuredeploy.json file

Testing Azure deployment can be done from Azure PowerShell something like this...

Switch-AzureMode -Name AzureResourceManager
$site = "uniqueNameARMTest123"
$pw = read-host -AsSecureString
New-AzureResourceGroup -TemplateFile .\azuredeploy.json -Name $site -DeploymentName $site `
    -Verbose -Location "South Central US" -hostingPlanName $site -hostingPlanLocation "South Central US" `
    -siteName $site -repoUrl "https://github.com/Durwella/UrlShortening" -branch "master" `
    -title $site -adminPassword $pw
# Testing...
Remove-AzureResourceGroup -Name $site