Пример #1
0
        //
        // GET: /Redirect/
        public ActionResult Index(String id)
        {
            // If "id" is null, probably user tried to visit the root of the domain, in which case
            // redirect them to the domain where you would have a landing page
            if(String.IsNullOrEmpty(id))
                Response.Redirect("");

            //1. Lookup the key from the cache or Store
            Object urlObj = _Cache.Get(id);
            if (urlObj == null)
            {
                UrlMap map = _UrlMapDS.FindByShortUrlKey(id);
                if (map == null)
                {
                    return new HttpNotFoundResult();
                }

                _Cache.Put(id, map.OriginalUrl);
                urlObj = map.OriginalUrl;
            }

            //Send a message to the Queue so we can track the request
            UrlRedirectMessage message = new UrlRedirectMessage
            {
                UrlKey=id,
                ActualUrl = urlObj.ToString(),
                AcceptLanguage = HttpContext.Request.Headers["Accept-Language"],
                VisitorIP = HttpContext.Request.UserHostAddress,
                UserAgent = HttpContext.Request.UserAgent,
                Referer = HttpContext.Request.UrlReferrer != null ? HttpContext.Request.UrlReferrer.ToString() : String.Empty
            };

            _UrlTrackerDS.SendUrlVisitedMessage(message);

            //Finally redirect
            return Redirect(urlObj.ToString());
        }
Пример #2
0
 public void SendUrlVisitedMessage(UrlRedirectMessage message)
 {
     _TrackerQueue.AddMessage(message);
 }