SessionInProcHandler.jvm.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. using System;
  32. using System.IO;
  33. using System.Collections;
  34. using System.Web;
  35. using System.Web.Hosting;
  36. using System.Web.Configuration;
  37. namespace System.Web.SessionState
  38. {
  39. class SessionInProcHandler : ISessionHandler
  40. {
  41. #if NET_2_0
  42. SessionStateSection config;
  43. #else
  44. SessionConfig config;
  45. #endif
  46. public void Dispose () { }
  47. public void Init (SessionStateModule module, HttpApplication context,
  48. #if NET_2_0
  49. SessionStateSection config
  50. #else
  51. SessionConfig config
  52. #endif
  53. )
  54. {
  55. this.config = config;
  56. }
  57. public void UpdateHandler (HttpContext context, SessionStateModule module) { }
  58. public HttpSessionState UpdateContext (HttpContext context, SessionStateModule module,
  59. bool required, bool read_only, ref bool isNew)
  60. {
  61. if (!required)
  62. return null;
  63. ServletWorkerRequest worker = (ServletWorkerRequest)context.Request.WorkerRequest;
  64. javax.servlet.http.HttpSession javaSession = worker.ServletRequest.getSession(false);
  65. HttpSessionState state;
  66. if (javaSession != null)
  67. {
  68. state = (HttpSessionState) javaSession.getAttribute("GH_SESSION_STATE");
  69. return state;
  70. }
  71. // We create a new session.
  72. javaSession = worker.ServletRequest.getSession(true);
  73. string sessionID = javaSession.getId();
  74. state = new HttpSessionState (sessionID, // unique identifier
  75. new SessionDictionary(), // dictionary
  76. HttpApplicationFactory.ApplicationState.SessionObjects,
  77. #if NET_2_0
  78. (int)config.Timeout.TotalMinutes, // XXX is this right? we lose some precision here, but since the timeout is in minutes *anyway*...
  79. #else
  80. config.Timeout, //lifetime before death.
  81. #endif
  82. true, //new session
  83. false, // is cookieless
  84. SessionStateMode.J2ee,
  85. read_only); //readonly
  86. javaSession.setAttribute("GH_SESSION_STATE", state);
  87. isNew = true;
  88. return state;
  89. }
  90. }
  91. }