Exemple #1
0
        public IActionResult Index(string id)
        {
            string    shortUrl  = string.Empty;
            string    result    = string.Empty;
            Shortener shortener = new Shortener(_configuration["connectionString"], _configuration["salt"]);

            if (string.IsNullOrEmpty(id))
            {
                //here we just show the Index
                try
                {
                    shortener.TestConnect();
                    result = "OK";
                }
                catch (Exception ex)
                {
                    result = ex.Message;
                }
                ViewData["host"]             = "https://" + Request.Host;
                ViewData["result"]           = result;
                ViewData["connectionString"] = _configuration["connectionString"];
                return(View());
            }
            else
            {
                try
                {
                    if (id.Length <= 12 && !string.IsNullOrEmpty(shortUrl = shortener.GetUrl(id)))
                    {
                        return(Redirect(shortUrl));
                    }
                }
                catch { }
            }
            Response.StatusCode = 404;
            //ViewData["id"] = Uri.EscapeDataString(id);
            return(View("NotFound"));
        }