public IActionResult Get(string path) { try { if (string.IsNullOrEmpty(path)) { return(BadRequest()); } var url = _shorturlservice.GetByPath(path); if (url == null) { return(NotFound()); } var visitor = _visitorService.GetCurrentVisitor(); _statsService.AddShortUrlStat(url, visitor); var uribuilder = new UriBuilder(url.OriginalUrl); if (HttpContext.Request.QueryString.HasValue) { var currentquerystring = HttpContext.Request.QueryString.Value; if (!string.IsNullOrEmpty(uribuilder.Query)) { currentquerystring = currentquerystring.Replace("?", "&"); } uribuilder.Query = string.Concat(uribuilder.Query, currentquerystring); } HttpContext.Response.Headers.Add("Location", uribuilder.Uri.AbsoluteUri); if (url.RedirectionCode == 0) { url.RedirectionCode = _settings.Value.Defaultredirectioncode; } return(new StatusCodeResult(url.RedirectionCode)); } catch (Exception ex) { var exc = ex.InnerException ?? ex; _loggerservice.LogError("Get error " + exc.Message); return(StatusCode((int)HttpStatusCode.InternalServerError, exc)); } }