File: SessionStateContainer.cs

package info (click to toggle)
mono 5.18.0.240%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,253,216 kB
  • sloc: cs: 10,925,936; xml: 2,804,987; ansic: 643,970; cpp: 120,384; perl: 59,272; asm: 21,383; sh: 20,162; makefile: 18,157; python: 4,715; pascal: 924; sql: 859; sed: 16; php: 1
file content (325 lines) | stat: -rw-r--r-- 9,682 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
//------------------------------------------------------------------------------
// <copyright file="SessionState.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>                                                                
//------------------------------------------------------------------------------

/*
 * HttpSessionState
 * 
 * Copyright (c) 1998-1999, Microsoft Corporation
 * 
 */

namespace System.Web.SessionState {

    using System.Threading;
    using System.Runtime.InteropServices;
    using System.Web;
    using System.Web.Util;
    using System.Collections;
    using System.Collections.Specialized;
    using System.Text;
    using System.Globalization;
    using System.Security.Permissions;

    public class HttpSessionStateContainer : IHttpSessionState {
        String                      _id;
        ISessionStateItemCollection      _sessionItems;
        HttpStaticObjectsCollection _staticObjects;
        int                         _timeout;
        bool                        _newSession;
        HttpCookieMode              _cookieMode;
        SessionStateMode            _mode;
        bool                        _abandon;
        bool                        _isReadonly;
        SessionStateModule          _stateModule;   // used for optimized InProc session id callback

        public HttpSessionStateContainer(
                                 String                      id, 
                                 ISessionStateItemCollection sessionItems,
                                 HttpStaticObjectsCollection staticObjects,
                                 int                         timeout,
                                 bool                        newSession,
                                 HttpCookieMode              cookieMode,
                                 SessionStateMode            mode,
                                 bool                        isReadonly) 
            : this(null, id, sessionItems, staticObjects, timeout, newSession, cookieMode, mode, isReadonly) {
            if (id == null) {
                throw new ArgumentNullException("id");
            }
        }

        internal HttpSessionStateContainer(
                                 SessionStateModule          stateModule, 
                                 string                      id,
                                 ISessionStateItemCollection      sessionItems,
                                 HttpStaticObjectsCollection staticObjects,
                                 int                         timeout,
                                 bool                        newSession,
                                 HttpCookieMode              cookieMode,
                                 SessionStateMode            mode,
                                 bool                        isReadonly) {
            _stateModule = stateModule;
            _id = id;   // If null, it means we're delaying session id reading
            _sessionItems = sessionItems;
            _staticObjects = staticObjects;
            _timeout = timeout;    
            _newSession = newSession; 
            _cookieMode = cookieMode;
            _mode = mode;
            _isReadonly = isReadonly;
        }

        internal HttpSessionStateContainer() {
        }

        /*
         * The Id of the session.
         */
        public String SessionID {
            get {
                if (_id == null) {
                    Debug.Assert(_stateModule != null, "_stateModule != null");
                    _id = _stateModule.DelayedGetSessionId();
                }
                return _id;
            }
        }

        /*
         * The length of a session before it times out, in minutes.
         */
        public int Timeout {
            get {return _timeout;}
            set {
                if (value <= 0) {
                    throw new ArgumentException(SR.GetString(SR.Timeout_must_be_positive));
                }

                if (value > SessionStateModule.MAX_CACHE_BASED_TIMEOUT_MINUTES &&
                    (Mode == SessionStateMode.InProc ||
                    Mode == SessionStateMode.StateServer)) {
                    throw new ArgumentException(
                        SR.GetString(SR.Invalid_cache_based_session_timeout));
                }

                _timeout = value;
            }
        }

        /*
         * Is this a new session?
         */

        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public bool IsNewSession {
            get {return _newSession;}
        }

        /*
         * Is session state in a separate process
         */

        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public SessionStateMode Mode {
            get {return _mode;}
        }

        /*
         * Is session state cookieless?
         */
        public bool IsCookieless {
            get {
                if (_stateModule != null) {
                    // See VSWhidbey 399907
                    return _stateModule.SessionIDManagerUseCookieless;
                }
                else {
                    // For container created by custom session state module,
                    // sorry, we currently don't have a way to tell and thus we rely blindly
                    // on cookieMode.
                    return CookieMode == HttpCookieMode.UseUri;
                }
            }
        }

        public HttpCookieMode CookieMode {
            get {return _cookieMode;}
        }

        /*
         * Abandon the session.
         * 
         */

        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public void Abandon() {
            _abandon = true;
        }


        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public int LCID {
            // 


            get { return Thread.CurrentThread.CurrentCulture.LCID; }
            set { Thread.CurrentThread.CurrentCulture = HttpServerUtility.CreateReadOnlyCultureInfo(value); }
        }


        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public int CodePage {
            // 


            get { 
                if (HttpContext.Current != null)
                    return HttpContext.Current.Response.ContentEncoding.CodePage;
                else
                    return Encoding.Default.CodePage;
            }
            set { 
                if (HttpContext.Current != null)
                    HttpContext.Current.Response.ContentEncoding = Encoding.GetEncoding(value);
            }
        }

        public bool IsAbandoned {
            get {return _abandon;}
        }

        public HttpStaticObjectsCollection StaticObjects {
            get { return _staticObjects;}
        }

        public Object this[String name]
        {
            get {
                return _sessionItems[name];
            }
            set {
                _sessionItems[name] = value;
            }
        }


        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public Object this[int index]
        {
            get {return _sessionItems[index];}
            set {_sessionItems[index] = value;}
        }
        

        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public void Add(String name, Object value) {
            _sessionItems[name] = value;        
        }


        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public void Remove(String name) {
            _sessionItems.Remove(name);
        }


        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public void RemoveAt(int index) {
            _sessionItems.RemoveAt(index);
        }


        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public void Clear() {
            _sessionItems.Clear();
        }


        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public void RemoveAll() {
            Clear();
        }


        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public int Count {
            get {return _sessionItems.Count;}
        }


        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public NameObjectCollectionBase.KeysCollection Keys {
            get {return _sessionItems.Keys;}
        }


        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public IEnumerator GetEnumerator() {
            return _sessionItems.GetEnumerator();
        }


        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public void CopyTo(Array array, int index) {
            for (IEnumerator e = this.GetEnumerator(); e.MoveNext();)
                array.SetValue(e.Current, index++);
        }


        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public Object SyncRoot {
            get { return this;}
        }


        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public bool IsReadOnly {
            get { return _isReadonly;}
        }


        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public bool IsSynchronized {
            get { return false;}
        }
    }
}