PageRenderTime 49ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/BaliEnterpriseSystems/BaliEnterpriseSystems/Global.asax.cs

https://github.com/sirivedula/BEST
C# | 102 lines | 86 code | 15 blank | 1 comment | 13 complexity | 2d8b9e4145f1bf46d4dfbfefc4d61246 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Security;
  6. using System.Web.SessionState;
  7. using System.Configuration;
  8. using BaliEnterpriseSystems.BestObjects;
  9. namespace BaliEnterpriseSystems
  10. {
  11. public class Global : System.Web.HttpApplication
  12. {
  13. protected void Application_Start(object sender, EventArgs e)
  14. {
  15. }
  16. protected void Session_Start(object sender, EventArgs e)
  17. {
  18. }
  19. protected void Application_BeginRequest(object sender, EventArgs e)
  20. {
  21. }
  22. protected void Application_AuthenticateRequest(object sender, EventArgs e)
  23. {
  24. }
  25. protected void Application_Error(object sender, EventArgs e)
  26. {
  27. Exception CurrentException = Server.GetLastError();
  28. string ErrorDetails = CurrentException.ToString();
  29. if (HttpContext.Current == null) return;
  30. string serverip = HttpContext.Current.Request.ServerVariables["LOCAL_ADDR"].ToString();
  31. var cUser = Utils.User;
  32. if (cUser != null)
  33. {
  34. ErrorDetails = "User Name:" + (cUser.BestUser.userName ?? "") + ErrorDetails;
  35. }
  36. if (HttpContext.Current.Request != null)
  37. {
  38. ErrorDetails = "<br />ServerIP:" + serverip + "<br />" + HttpUtility.HtmlEncode(ErrorDetails);
  39. ErrorDetails += "<br />Referrer:" + HttpUtility.HtmlEncode(HttpContext.Current.Request.UrlReferrer.ToString());
  40. ErrorDetails += "<br />User Agent:" + HttpUtility.HtmlEncode(HttpContext.Current.Request.UserAgent);
  41. ErrorDetails += "<br />User IP:" + HttpUtility.HtmlEncode(HttpContext.Current.Request.UserHostAddress);
  42. if (ConfigurationManager.AppSettings["ShowTerribleErrors"].Equals("true"))
  43. {
  44. Response.Write(HttpUtility.HtmlEncode(ErrorDetails));
  45. }
  46. else
  47. {
  48. // Send notification e-mail
  49. string toaddress = ConfigurationManager.AppSettings["FromEMail"];
  50. Utils.User.emailUtil.Send(toaddress, "Best - Error", ErrorDetails, "BEST");
  51. if (!CurrentException.ToString().Contains("SiteError.aspx"))
  52. {
  53. Response.Redirect("SiteError.aspx");
  54. }
  55. else
  56. {
  57. Response.Write("There has been an error - Unable to redirect to the error notification page.");
  58. }
  59. }
  60. }
  61. }
  62. protected void Session_End(object sender, EventArgs e)
  63. {
  64. if (HttpContext.Current != null)
  65. {
  66. var sessguid = HttpContext.Current.Session["SessionGuid"];
  67. if (sessguid != null)
  68. {
  69. BestField sguid = new BestField() { fieldName = "sessionguid", fieldType = "System.Guid", paramOledbType = System.Data.OleDb.OleDbType.Guid, fieldSize = 40 };
  70. sguid.fieldValue = sessguid.ToString();
  71. BestLogins bslog = new BestLogins();
  72. List<BestField> bparam = new List<BestField>();
  73. bparam.Add(sguid);
  74. bslog.LoadRows("sessionguid=?", bparam);
  75. if (bslog.TableRows.Count > 0)
  76. {
  77. bslog.logoutdate = DateTime.Now;
  78. bslog.CurrentRow.Save();
  79. }
  80. }
  81. }
  82. }
  83. protected void Application_End(object sender, EventArgs e)
  84. {
  85. }
  86. }
  87. }