public async Task <IActionResult> Index(string token) { var shortUrl = await _shortUrlRepository.FindByToken(token); if (shortUrl == null) { return(NotFound()); } // Check if short url's expiration if (shortUrl.ExpiresAt.HasValue && shortUrl.ExpiresAt.Value < DateTime.Now) { return(NotFound()); } var clientInfo = Parser.GetDefault().Parse(Request.Headers["User-Agent"]); // TODO: Use NLog for this // Log usage info var usageLog = new UsageLog { ShortUrlId = shortUrl.Id, ClientIP = HttpContext.Connection.RemoteIpAddress.ToString(), ClientBrowser = clientInfo.UA.Family, ClientDevice = clientInfo.Device.Family, ClientOS = clientInfo.OS.Family }; await _usageLogRepository.Create(usageLog); return(Redirect(shortUrl.OriginalUrl)); }