SessionInProcHandler.jvm.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //
  2. // System.Web.SessionState.SesionInProchandler.jvm.cs
  3. //
  4. // Authors:
  5. // Ilya Kharmatsky ([email protected])
  6. // Alon Gazit
  7. // Pavel Sandler
  8. //
  9. // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
  10. //
  11. //
  12. // Permission is hereby granted, free of charge, to any person obtaining
  13. // a copy of this software and associated documentation files (the
  14. // "Software"), to deal in the Software without restriction, including
  15. // without limitation the rights to use, copy, modify, merge, publish,
  16. // distribute, sublicense, and/or sell copies of the Software, and to
  17. // permit persons to whom the Software is furnished to do so, subject to
  18. // the following conditions:
  19. //
  20. // The above copyright notice and this permission notice shall be
  21. // included in all copies or substantial portions of the Software.
  22. //
  23. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  27. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  28. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  29. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  30. //
  31. #if !NET_2_0
  32. using System;
  33. using System.IO;
  34. using System.Collections;
  35. using System.Web;
  36. using System.Web.Hosting;
  37. using System.Web.Configuration;
  38. namespace System.Web.SessionState
  39. {
  40. class SessionInProcHandler : ISessionHandler
  41. {
  42. #if NET_2_0
  43. SessionStateSection config;
  44. #else
  45. SessionConfig config;
  46. #endif
  47. public void Dispose () { }
  48. public void Init (SessionStateModule module, HttpApplication context,
  49. #if NET_2_0
  50. SessionStateSection config
  51. #else
  52. SessionConfig config
  53. #endif
  54. )
  55. {
  56. this.config = config;
  57. }
  58. public void UpdateHandler (HttpContext context, SessionStateModule module) { }
  59. public HttpSessionState UpdateContext (HttpContext context, SessionStateModule module,
  60. bool required, bool read_only, ref bool isNew)
  61. {
  62. if (!required)
  63. return null;
  64. ServletWorkerRequest worker = (ServletWorkerRequest)context.Request.WorkerRequest;
  65. javax.servlet.http.HttpSession javaSession = worker.ServletRequest.getSession(false);
  66. HttpSessionState state;
  67. if (javaSession != null)
  68. {
  69. state = (HttpSessionState) javaSession.getAttribute("GH_SESSION_STATE");
  70. return state;
  71. }
  72. // We create a new session.
  73. javaSession = worker.ServletRequest.getSession(true);
  74. string sessionID = javaSession.getId();
  75. state = new HttpSessionState (sessionID, // unique identifier
  76. new SessionDictionary(), // dictionary
  77. HttpApplicationFactory.ApplicationState.SessionObjects,
  78. #if NET_2_0
  79. (int)config.Timeout.TotalMinutes, // XXX is this right? we lose some precision here, but since the timeout is in minutes *anyway*...
  80. #else
  81. config.Timeout, //lifetime before death.
  82. #endif
  83. true, //new session
  84. false, // is cookieless
  85. SessionStateMode.J2ee,
  86. read_only); //readonly
  87. javaSession.setAttribute("GH_SESSION_STATE", state);
  88. isNew = true;
  89. return state;
  90. }
  91. }
  92. }
  93. #endif