Exemple #1
0
        public ActionResult Preview(ShortUrlVisitCommand command)
        {
            Check.Argument.IsNotNull(command, "command");

            ShortUrlResult result = shortUrlService.GetByAlias(command.Alias);

            ModelState.Merge(result.RuleViolations);

            if (result.ShortUrl == null)
            {
                return(new NotFoundResult());
            }

            return(View(result.ShortUrl));
        }
Exemple #2
0
        public ActionResult Visit(ShortUrlVisitCommand command)
        {
            Check.Argument.IsNotNull(command, "command");

            bool sameDomain = !string.IsNullOrWhiteSpace(command.Referrer) && command.Referrer.StartsWith(Url.ApplicationRoot(), StringComparison.OrdinalIgnoreCase);

            if (!sameDomain)
            {
                ShortUrlResult shortUrlResult = shortUrlService.GetByAlias(command.Alias);
                ShortUrlDTO    shortUrl       = shortUrlResult.ShortUrl;

                if (shortUrl == null)
                {
                    return(new NotFoundResult());
                }

                if (shortUrl.SpamStatus.IsSpam())
                {
                    return(RedirectToAction("Preview", new { alias = shortUrl.Alias }));
                }
            }

            if (sameDomain)
            {
                command.Referrer = null;
            }

            VisitResult visitResult = shortUrlService.Visit(command.Alias, command.IPAddress, command.Browser, command.Referrer);

            ModelState.Merge(visitResult.RuleViolations);

            if (visitResult.Visit == null)
            {
                return(new NotFoundResult());
            }

            string url = visitResult.Visit.Url;

            return(settings.RedirectPermanently ? new PermanentRedirectResult(url) : Redirect(url));
        }