Global.asax.cs 3.0 KB

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