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.

TrackDownload.cs 1.0KB

123456789101112131415161718192021222324252627282930313233343536
  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 System.Web.UI;
  9. using Teknik.Configuration;
  10. using Teknik.Helpers;
  11. namespace Teknik.Filters
  12. {
  13. public class TrackDownload : 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. // Fire and forget. Don't need to wait for it.
  23. Task.Run(() => AsyncTrackDownload(request, request.Url.ToString()));
  24. base.OnActionExecuted(filterContext);
  25. }
  26. private void AsyncTrackDownload(HttpRequestBase request, string url)
  27. {
  28. Config config = Config.Load();
  29. Tracking.TrackDownload(request, config, url);
  30. }
  31. }
  32. }