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.

70 lines
2.0 KiB

4 years ago
4 years ago
  1. #if NET40 || NET461
  2. // global.ashx
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Web;
  6. using System.Web.Routing;
  7. namespace Apewer.Web
  8. {
  9. /// <summary></summary>
  10. public class WebsiteGlobal : HttpApplication
  11. {
  12. /// <summary></summary>
  13. public WebsiteGlobal() { }
  14. /// <summary></summary>
  15. protected virtual void Application_Start(object sender, EventArgs e) { }
  16. /// <summary></summary>
  17. protected virtual void Application_End(object sender, EventArgs e) { }
  18. /// <summary></summary>
  19. protected virtual void Application_Error(object sender, EventArgs e) { }
  20. /// <summary></summary>
  21. protected virtual void Application_BeginRequest(object sender, EventArgs e) { }
  22. /// <summary></summary>
  23. protected virtual void Application_AuthenticateRequest(object sender, EventArgs e) { }
  24. /// <summary></summary>
  25. protected virtual void Session_Start(object sender, EventArgs e) { }
  26. /// <summary></summary>
  27. protected virtual void Session_End(object sender, EventArgs e) { }
  28. /// <summary>路由处理所有请求(包括指向文件的请求),与定义的模式匹配的所有请求都由路由处理。</summary>
  29. protected void AddRouter(bool value = true)
  30. {
  31. RouteTable.Routes.RouteExistingFiles = value;
  32. }
  33. /// <summary>添加路由。</summary>
  34. protected void AddRouter(string url, string path)
  35. {
  36. if (string.IsNullOrEmpty(url) || string.IsNullOrEmpty(path)) return;
  37. RouteTable.Routes.MapPageRoute("", url, path, false);
  38. }
  39. /// <summary>添加路由。</summary>
  40. protected void AddRouter(Dictionary<string, string> rules)
  41. {
  42. // rules.Add("api", "~/api.aspx");
  43. // rules.Add("{app}/{function}/{*args}", "~/app.aspx");
  44. if (rules == null) return;
  45. foreach (var rule in rules)
  46. {
  47. AddRouter(rule.Key, rule.Value);
  48. }
  49. }
  50. }
  51. }
  52. #endif