The next generation of the Teknik Services. Written in ASP.NET. https://www.teknik.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TrackLink.cs 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using Microsoft.AspNetCore.Http;
  2. using Microsoft.AspNetCore.Http.Extensions;
  3. using Microsoft.AspNetCore.Mvc.Filters;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Web;
  10. using Teknik.Configuration;
  11. using Teknik.Tracking;
  12. using Teknik.Utilities;
  13. namespace Teknik.Filters
  14. {
  15. public class TrackLink : ActionFilterAttribute
  16. {
  17. private readonly Config _config;
  18. public TrackLink(Config config)
  19. {
  20. _config = config;
  21. }
  22. public override void OnActionExecuting(ActionExecutingContext filterContext)
  23. {
  24. }
  25. public override void OnActionExecuted(ActionExecutedContext filterContext)
  26. {
  27. HttpRequest request = filterContext.HttpContext.Request;
  28. string doNotTrack = request.Headers["DNT"];
  29. if (string.IsNullOrEmpty(doNotTrack) || doNotTrack != "1")
  30. {
  31. string userAgent = request.Headers["User-Agent"].ToString();
  32. string clientIp = request.ClientIPFromRequest(true);
  33. string urlReferrer = request.Headers["Referer"].ToString();
  34. string url = UriHelper.GetEncodedUrl(request);
  35. // Fire and forget. Don't need to wait for it.
  36. Tracking.Tracking.TrackLink(filterContext.HttpContext, _config, userAgent, clientIp, url, urlReferrer);
  37. }
  38. }
  39. }
  40. }