Global.asax.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using System.Web;
  3. using System.Web.Mvc;
  4. using System.Web.Routing;
  5. using System.Web.Http;
  6. using SysBaseLibs;
  7. namespace Gs.DataPush.WebApi
  8. {
  9. public class Global : HttpApplication
  10. {
  11. void Application_Start(object sender, EventArgs e)
  12. {
  13. // 在应用程序启动时运行的代码
  14. AreaRegistration.RegisterAllAreas();
  15. GlobalConfiguration.Configure(WebApiConfig.Register);
  16. RouteConfig.RegisterRoutes(RouteTable.Routes);
  17. log4net.Config.XmlConfigurator.Configure();
  18. string lcVpath = AppDomain.CurrentDomain.BaseDirectory;
  19. SysSecLibs.FileFuns.AddSeachingFolder(lcVpath + "Bin");
  20. this.LogInfo("Application_Start -- System Begin Start!");
  21. }
  22. protected void Application_End(object sender, EventArgs e)
  23. {
  24. // 在应用程序关闭时运行的代码
  25. this.LogInfo("Application_End -- System End!");
  26. }
  27. protected void Application_Error(object sender, EventArgs e)
  28. {
  29. // 在出现未处理的错误时运行的代码
  30. //获取到HttpUnhandledException异常,这个异常包含一个实际出现的异常
  31. Exception ex = Server.GetLastError();
  32. //实际发生的异常
  33. Exception innerException = ex.InnerException;
  34. if (innerException != null) ex = innerException;
  35. this.LogFatal(ex);
  36. }
  37. protected void Session_Start(object sender, EventArgs e)
  38. {
  39. // 在新会话启动时运行的代码
  40. this.LogInfo("Session_Start");
  41. }
  42. protected void Session_End(object sender, EventArgs e)
  43. {
  44. // 在会话结束时运行的代码。
  45. // 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为 InProc 时,才会引发 Session_End 事件。
  46. // 如果会话模式设置为 StateServer
  47. // 或 SQLServer,则不会引发该事件。
  48. this.LogInfo("Session_End");
  49. }
  50. }
  51. }