/Docs/07-Implementacion/Source/trunk/EDUAR_actual/EDUAR/EDUAR_UI/Global.asax.cs

http://blpm.googlecode.com/ · C# · 99 lines · 54 code · 12 blank · 33 comment · 6 complexity · 51e23a75fc123ad4ba206710bd1b51a6 MD5 · raw file

  1. using System;
  2. using System.IO;
  3. using EDUAR_UI.Utilidades;
  4. using System.Web;
  5. using System.Web.Security;
  6. using System.Security.Principal;
  7. namespace EDUAR_UI
  8. {
  9. public class Global : System.Web.HttpApplication
  10. {
  11. void Application_Start(object sender, EventArgs e)
  12. {
  13. // Código que se ejecuta al iniciarse la aplicación
  14. }
  15. void Application_End(object sender, EventArgs e)
  16. {
  17. // Código que se ejecuta cuando se cierra la aplicación
  18. }
  19. void Application_Error(object sender, EventArgs e)
  20. {
  21. // Código que se ejecuta al producirse un error no controlado
  22. //string error = "Se produjo un error: \n" +
  23. //if (Server.GetLastError() != null)
  24. //{
  25. // Application["CurrentError"] = Server.GetLastError().Message.ToString();
  26. // Application["CurrentErrorDetalle"] = Server.GetLastError().ToString();
  27. //}
  28. ////Response.Redirect("~/Error.aspx", false);
  29. //Server.Transfer("~/Error.aspx");
  30. }
  31. protected void Application_BeginRequest(Object sender, EventArgs e)
  32. {
  33. switch (Request.Url.Scheme)
  34. {
  35. case "https":
  36. if (Request.Url.PathAndQuery.Contains("Public") || Request.Url.PathAndQuery.Contains("Default") ||
  37. Request.Url.PathAndQuery.Contains("About") || Request.Url.PathAndQuery.Contains("Error"))
  38. {
  39. var path = "http://" + Request.Url.Host + Request.Url.PathAndQuery;
  40. Response.Status = "301 Moved Permanently";
  41. Response.AddHeader("Location", path);
  42. }
  43. else
  44. Response.AddHeader("Strict-Transport-Security", "max-age=300");
  45. break;
  46. case "http":
  47. if (Request.Url.PathAndQuery.Contains("Login") || Request.Url.PathAndQuery.Contains("Private"))
  48. {
  49. var path = "https://" + Request.Url.Host + Request.Url.PathAndQuery;
  50. Response.Status = "301 Moved Permanently";
  51. Response.AddHeader("Location", path);
  52. }
  53. break;
  54. }
  55. }
  56. void Session_Start(object sender, EventArgs e)
  57. {
  58. // Código que se ejecuta cuando se inicia una nueva sesión
  59. }
  60. void Session_End(object sender, EventArgs e)
  61. {
  62. // Código que se ejecuta cuando finaliza una sesión.
  63. UIUtilidades.EliminarArchivosSession(Session.SessionID);
  64. // Nota: el evento Session_End se desencadena sólo cuando el modo sessionstate
  65. // se establece como InProc en el archivo Web.config. Si el modo de sesión se establece como StateServer
  66. // o SQLServer, el evento no se genera.
  67. Session.Abandon();
  68. }
  69. //protected void Application_AuthenticateRequest(Object sender, EventArgs e)
  70. //{
  71. // //Fires upon attempting to authenticate the use
  72. // if (!(HttpContext.Current.User == null))
  73. // {
  74. // if (HttpContext.Current.User.Identity.IsAuthenticated)
  75. // {
  76. // if (HttpContext.Current.User.Identity.GetType() == typeof(FormsIdentity))
  77. // {
  78. // FormsIdentity fi = (FormsIdentity)HttpContext.Current.User.Identity;
  79. // FormsAuthenticationTicket fat = fi.Ticket;
  80. // String[] astrRoles = fat.UserData.Split('|');
  81. // HttpContext.Current.User = new GenericPrincipal(fi, astrRoles);
  82. // }
  83. // }
  84. // }
  85. //}
  86. }
  87. }