Created
September 2, 2017 15:00
-
-
Save JeremyLikness/ae8dfcfbaf55a9b6c674b0d40482f280 to your computer and use it in GitHub Desktop.
Redirect function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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