/source/app/NOS.Root/JSONPHandler.ashx

http://github.com/agross/netopenspace · Unknown · 52 lines · 45 code · 7 blank · 0 comment · 0 complexity · 8f036096f3313b0c0e5bdea1057bcefc MD5 · raw file

  1. <%@ WebHandler Language="C#" Class="JSONPHandler" %>
  2. using System;
  3. using System.IO;
  4. using System.Web;
  5. public class JSONPHandler : IHttpHandler
  6. {
  7. public void ProcessRequest (HttpContext context)
  8. {
  9. string callback = context.Request.QueryString["json"];
  10. string file = context.Request.QueryString["file"];
  11. try
  12. {
  13. context.Response.ContentType = "text/javascript";
  14. context.Response.AddHeader("X-Content-Type-Options", "nosniff");
  15. context.Response.Cache.SetLastModified(File.GetLastWriteTimeUtc(context.Server.MapPath(file)));
  16. context.Response.Cache.SetCacheability(HttpCacheability.Public);
  17. context.Response.Cache.SetSlidingExpiration(true);
  18. context.Response.Cache.SetExpires(DateTime.Now.AddDays(30));
  19. context.Response.Cache.SetMaxAge(TimeSpan.FromDays(30));
  20. context.Response.Cache.SetNoTransforms();
  21. if (!String.IsNullOrEmpty(callback))
  22. {
  23. //context.Response.Write("alert('hit');");
  24. context.Response.Write(callback + "(");
  25. }
  26. context.Response.TransmitFile(file);
  27. if (!String.IsNullOrEmpty(callback))
  28. {
  29. context.Response.Write(");");
  30. }
  31. }
  32. catch(FileNotFoundException)
  33. {
  34. context.Response.Clear();
  35. context.Response.StatusCode = 404;
  36. }
  37. }
  38. public bool IsReusable
  39. {
  40. get
  41. {
  42. return true;
  43. }
  44. }
  45. }