Skip to content

Instantly share code, notes, and snippets.

@JeremyLikness
Created September 2, 2017 15:00
Show Gist options
  • Select an option

  • Save JeremyLikness/ae8dfcfbaf55a9b6c674b0d40482f280 to your computer and use it in GitHub Desktop.

Select an option

Save JeremyLikness/ae8dfcfbaf55a9b6c674b0d40482f280 to your computer and use it in GitHub Desktop.
Redirect function
public static HttpResponseMessage Run(HttpRequestMessage req, CloudTable inputTable,
string shortUrl, TraceWriter log)
{
var redirectUrl = FALLBACK_URL;
if (!String.IsNullOrWhiteSpace(shortUrl))
{
shortUrl = shortUrl.Trim().ToLower();
var partitionKey = $"{shortUrl.First()}";
TableOperation operation = TableOperation.Retrieve<ShortUrl>(partitionKey, shortUrl);
TableResult result = inputTable.Execute(operation);
ShortUrl fullUrl = result.Result as ShortUrl;
if (fullUrl != null)
{
redirectUrl = WebUtility.UrlDecode(fullUrl.Url);
}
}
var res = req.CreateResponse(HttpStatusCode.Redirect);
res.Headers.Add("Location", redirectUrl);
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment