The next generation of the Teknik Services. Written in ASP.NET. https://www.teknik.io/
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

TrackLink.cs 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Web;
  7. using System.Web.Mvc;
  8. using Teknik.Configuration;
  9. using Teknik.Piwik;
  10. using Teknik.Utilities;
  11. namespace Teknik.Filters
  12. {
  13. public class TrackLink : ActionFilterAttribute
  14. {
  15. public override void OnActionExecuting(ActionExecutingContext filterContext)
  16. {
  17. base.OnActionExecuting(filterContext);
  18. }
  19. public override void OnActionExecuted(ActionExecutedContext filterContext)
  20. {
  21. HttpRequestBase request = filterContext.HttpContext.Request;
  22. string doNotTrack = request.Headers["DNT"];
  23. if (string.IsNullOrEmpty(doNotTrack) || doNotTrack != "1")
  24. {
  25. string userAgent = request.UserAgent;
  26. string ipAddress = request.ClientIPFromRequest(true);
  27. string urlReferrer = request.UrlReferrer?.ToString();
  28. string url = string.Empty;
  29. if (request.Url != null)
  30. url = request.Url.ToString();
  31. // Fire and forget. Don't need to wait for it.
  32. Task.Run(() => AsyncTrackLink(userAgent, ipAddress, url, urlReferrer));
  33. }
  34. base.OnActionExecuted(filterContext);
  35. }
  36. private static void AsyncTrackLink(string userAgent, string clientIp, string url, string urlReferrer)
  37. {
  38. Tracking.TrackLink(userAgent, clientIp, url, urlReferrer);
  39. }
  40. }
  41. }