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.

43 lines
1.3 KiB

2 years ago
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Web;
  4. namespace EasyBL.Handler
  5. {
  6. /// <summary>
  7. /// Handler 的摘要说明
  8. /// </summary>
  9. public abstract class Handler
  10. {
  11. protected Handler(HttpContext context)
  12. {
  13. this.Request = context.Request;
  14. this.Response = context.Response;
  15. this.Context = context;
  16. this.Server = context.Server;
  17. }
  18. public abstract void Process();
  19. protected void WriteJson(object response)
  20. {
  21. var jsonpCallback = Request["callback"];
  22. var json = JsonConvert.SerializeObject(response);
  23. if (String.IsNullOrWhiteSpace(jsonpCallback))
  24. {
  25. Response.AddHeader("Content-Type", "text/plain");
  26. Response.Write(json);
  27. }
  28. else
  29. {
  30. Response.AddHeader("Content-Type", "application/javascript");
  31. Response.Write($"{jsonpCallback}({json});");
  32. }
  33. Response.End();
  34. }
  35. public HttpRequest Request { get; private set; }
  36. public HttpResponse Response { get; private set; }
  37. public HttpContext Context { get; private set; }
  38. public HttpServerUtility Server { get; private set; }
  39. }
  40. }