Global.asax.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System;
  2. using System.IO;
  3. using System.Web;
  4. using Abp.Castle.Logging.Log4Net;
  5. using Abp.Dependency;
  6. using Abp.PlugIns;
  7. using Abp.Timing;
  8. using Abp.Web;
  9. using Abp.Web.Localization;
  10. using Castle.Facilities.Logging;
  11. using IwbZero.ToolCommon;
  12. using IwbZero.ToolCommon.LogHelpers;
  13. namespace WeEngine
  14. {
  15. public class MvcApplication : AbpWebApplication<WeEngineWebModule>
  16. {
  17. protected override void Application_Start(object sender, EventArgs e)
  18. {
  19. AbpBootstrapper.IocManager.IocContainer.AddFacility<LoggingFacility>(
  20. f => f.UseAbpLog4Net().WithConfig(Server.MapPath("log4net.config"))
  21. );
  22. this.LogInfo("Application -- System Starting!");
  23. var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "PlugIns");
  24. AbpBootstrapper.PlugInSources.AddFolder(path);
  25. this.LogInfo($"Application -- PlugIns Path:{path}");
  26. base.Application_Start(sender, e);
  27. this.LogInfo("Application -- System Started!");
  28. }
  29. protected override void Application_End(object sender, EventArgs e)
  30. {
  31. "http://shvber.com:5016/".RequestGet("");
  32. // 在应用程序关闭时运行的代码
  33. this.LogInfo("Application -- System End!");
  34. }
  35. protected override void Application_Error(object sender, EventArgs e)
  36. {
  37. // 在出现未处理的错误时运行的代码
  38. //获取到HttpUnhandledException异常,这个异常包含一个实际出现的异常
  39. Exception ex = Server.GetLastError();
  40. //实际发生的异常
  41. Exception innerException = ex.InnerException;
  42. if (innerException != null) ex = innerException;
  43. this.LogFatal(ex);
  44. }
  45. protected override void Application_BeginRequest(object sender, EventArgs e)
  46. {
  47. var langCookie = Request.Cookies[WeEngineConst.LocalizationCookieName];
  48. if (langCookie == null)
  49. {
  50. Context.Response.SetCookie(
  51. new HttpCookie(WeEngineConst.LocalizationCookieName, "zh-Hans")
  52. {
  53. Expires = Clock.Now.AddYears(2),
  54. Path = Context.Request.ApplicationPath
  55. }
  56. );
  57. }
  58. base.Application_BeginRequest(sender, e);
  59. }
  60. protected override void Session_Start(object sender, EventArgs e)
  61. {
  62. // 在新会话启动时运行的代码
  63. this.LogInfo("Session_Start");
  64. }
  65. protected override void Session_End(object sender, EventArgs e)
  66. {
  67. // 在会话结束时运行的代码。
  68. // 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为 InProc 时,才会引发 Session_End 事件。
  69. // 如果会话模式设置为 StateServer
  70. // 或 SQLServer,则不会引发该事件。
  71. this.LogInfo("Session_End");
  72. }
  73. protected override void SetCurrentCulture()
  74. {
  75. AbpBootstrapper.IocManager.Using<ICurrentCultureSetter>(cultureSetter => cultureSetter.SetCurrentCulture(Context));
  76. }
  77. }
  78. }