DHandler.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Web;
  6. using System.IO;
  7. namespace Ant.Common
  8. {
  9. /// <summary>
  10. /// 后缀为HTML的,都经这里处理
  11. /// web.config
  12. /// <add verb="*" path="*.html" type="DCommon.DHandler"/>
  13. /// </summary>
  14. public class DHandlerHTML : IHttpHandler
  15. {
  16. public bool IsReusable
  17. {
  18. get { return false; }
  19. }
  20. /// <summary>
  21. /// 获取物理路径,判断文件夹中有没有存在这个文件
  22. /// 不存在的话,就会调用FilterStream类进行创建,并写入内容
  23. /// 存在的话,就直接显示页面
  24. /// </summary>
  25. public void ProcessRequest(HttpContext context)
  26. {
  27. HttpRequest request = context.Request;
  28. HttpResponse response = context.Response;
  29. string htmlPage = request.Url.AbsolutePath;
  30. string file = context.Server.MapPath(htmlPage);
  31. if (!File.Exists(file))
  32. {
  33. string aspxPage = DHelper.HtmlToAspx(htmlPage);
  34. response.Redirect(aspxPage);
  35. return;
  36. }
  37. response.WriteFile(file);
  38. return;
  39. }
  40. }
  41. /// <summary>
  42. /// 后缀为HTML的,都经这里处理
  43. /// web.config
  44. /// <add verb="*" path="*.html" type="DCommon.DHandler"/>
  45. /// </summary>
  46. public class DHandlerIMG : IHttpHandler
  47. {
  48. public bool IsReusable
  49. {
  50. get { return false; }
  51. }
  52. /// <summary>
  53. /// 获取物理路径,判断文件夹中有没有存在这个文件
  54. /// 不存在的话,就会调用FilterStream类进行创建,并写入内容
  55. /// 存在的话,就直接显示页面
  56. /// </summary>
  57. public void ProcessRequest(HttpContext context)
  58. {
  59. HttpRequest request = context.Request;
  60. HttpResponse response = context.Response;
  61. string htmlPage = request.Url.AbsolutePath;
  62. string file = context.Server.MapPath(htmlPage);
  63. if (!File.Exists(file))
  64. {
  65. response.Redirect("/UpFile/NoImg.jpg");
  66. return;
  67. }
  68. response.WriteFile(file);
  69. return;
  70. }
  71. }
  72. }