2
0

SessionStateModule.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //
  2. // System.Web.SessionState.SesionStateModule
  3. //
  4. // Authors:
  5. // Gonzalo Paniagua Javier ([email protected])
  6. // Stefan Görling ([email protected])
  7. //
  8. // (C) 2002,2003 Ximian, Inc (http://www.ximian.com)
  9. // (C) 2003 Stefan Görling (http://www.gorling.se)
  10. using System.Web;
  11. namespace System.Web.SessionState
  12. {
  13. [MonoTODO]
  14. public sealed class SessionStateModule : IHttpModule, IRequiresSessionState
  15. {
  16. static SessionConfig config;
  17. Type handlerType;
  18. ISessionHandler handler;
  19. public SessionStateModule ()
  20. {
  21. }
  22. public void Dispose ()
  23. {
  24. if (handler!=null)
  25. handler.Dispose();
  26. }
  27. [MonoTODO]
  28. public void Init (HttpApplication app)
  29. {
  30. if (config == null) {
  31. config = (SessionConfig) HttpContext.GetAppConfig ("system.web/sessionState");
  32. if (config == null)
  33. config = new SessionConfig (null);
  34. if (config.Mode == SessionStateMode.StateServer ||
  35. config.Mode == SessionStateMode.SQLServer)
  36. throw new NotSupportedException ("Only Off and InProc modes supported.");
  37. if (config.Mode == SessionStateMode.InProc) {
  38. handlerType = typeof (SessionInProcHandler);
  39. app.AddOnAcquireRequestStateAsync (
  40. new BeginEventHandler (OnBeginAcquireState),
  41. new EndEventHandler (OnEndAcquireState));
  42. app.ReleaseRequestState += new EventHandler (OnReleaseRequestState);
  43. app.EndRequest += new EventHandler (OnEndRequest);
  44. }
  45. }
  46. if (handlerType != null && handler == null) {
  47. handler = (ISessionHandler) Activator.CreateInstance (handlerType);
  48. handler.Init(app); //initialize
  49. }
  50. }
  51. void OnReleaseRequestState (object o, EventArgs args)
  52. {
  53. }
  54. void OnEndRequest (object o, EventArgs args)
  55. {
  56. }
  57. IAsyncResult OnBeginAcquireState (object o, EventArgs args, AsyncCallback cb, object data)
  58. {
  59. HttpApplication application = (HttpApplication) o;
  60. HttpContext context = application.Context;
  61. if (handler!=null)
  62. handler.UpdateContext (context);
  63. // In the future, we might want to move the Async stuff down to
  64. // the interface level, if we're going to support other than
  65. // InProc, we might actually want to do things async, now we
  66. // simply fake it.
  67. HttpAsyncResult result=new HttpAsyncResult (cb,this);
  68. result.Complete (true, o, null);
  69. return result;
  70. }
  71. void OnEndAcquireState (IAsyncResult result)
  72. {
  73. }
  74. public event EventHandler Start;
  75. public event EventHandler End;
  76. }
  77. }