details, details
[mono.git] / mcs / class / System.Web / System.Web.SessionState / SessionInProcHandler.cs
1 //
2 // System.Web.SessionState.SessionInProcHandler
3 //
4 // Authors:
5 //      Stefan Görling (stefan@gorling.se)
6 //      Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 //
8 // (C) 2003 Stefan Görling
9 // Copyright (c) 2004 Novell, Inc. (http://www.novell.com)
10 //
11
12 using System;
13 using System.IO;
14 using System.Collections;
15 using System.Web.Caching;
16
17 namespace System.Web.SessionState
18 {
19         class SessionInProcHandler : ISessionHandler
20         {
21                 SessionConfig config;
22                 CacheItemRemovedCallback removedCB;
23                 
24                 public void Dispose () { }
25
26                 public void Init (SessionStateModule module, HttpApplication context, SessionConfig config)
27                 {
28                         removedCB = new CacheItemRemovedCallback (module.OnSessionRemoved);
29                         this.config = config;
30                 }
31
32                 public void UpdateHandler (HttpContext context, SessionStateModule module) { }
33
34                 public HttpSessionState UpdateContext (HttpContext context, SessionStateModule module,
35                                                         bool required, bool read_only, ref bool isNew)
36                 {
37                         if (!required)
38                                 return null;
39
40                         Cache cache = HttpRuntime.Cache;
41                         HttpSessionState state = null;
42                         string id = SessionId.Lookup (context.Request, config.CookieLess);
43                         
44                         if (id != null) {
45                                 state = (HttpSessionState) cache ["@@@InProc@" + id];
46                                 if (state != null)
47                                         return state;
48                         }
49
50                         // Create a new session.
51                         string sessionID = SessionId.Create (module.Rng);
52                         state = new HttpSessionState (sessionID, // unique identifier
53                                                 new SessionDictionary(), // dictionary
54                                                 HttpApplicationFactory.ApplicationState.SessionObjects,
55                                                 config.Timeout, //lifetime before death.
56                                                 true, //new session
57                                                 false, // is cookieless
58                                                 SessionStateMode.InProc,
59                                                 read_only); //readonly
60
61                         TimeSpan timeout = new TimeSpan (0, config.Timeout, 0);
62                         cache.Insert ("@@@InProc@" + sessionID, state, null, DateTime.Now + timeout,
63                                         timeout, CacheItemPriority.AboveNormal, removedCB);
64
65                         isNew = true;
66                         return state;
67                 }
68         }
69 }
70