Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,221 @@
2010-02-24 Marek Habersack <mhabersack@novell.com>
* SessionStateServerHandler.cs, SessionSQLServerHandler.cs: added
support for session state compression (4.0)
2010-01-20 Marek Habersack <mhabersack@novell.com>
* SessionStateBehavior.cs: added (4.0)
2009-10-19 Marek Habersack <mhabersack@novell.com>
* SessionStateModule.cs: enabled SQL session state provider.
* SessionSQLServerHandler.cs: implemented. Uses System.Data.Common
for provider-agnostic implementation. Until an issue with Npgsql's
2.0 factory missing is resolved it defaults to using
Mono.Data.Sqlite as the provider.
Selecting of the data provider is done by putting DbProviderName
in the connection string specified in the
<system.web/sessionState> configuration section.
2009-03-21 Marek Habersack <mhabersack@novell.com>
* HttpSessionState.cs: implemented the CookieMode property.
2008-09-15 Marek Habersack <mhabersack@novell.com>
* SessionStateModule.cs: correctly let the handler know if an item
is new when calling SetAndReleaseItemExclusive. Fixes bug #424797
If handler's GetItem doesn't initialize storeLockId to a non-null
value, initialize it to 0. Fixes bug #424797
2008-07-29 Marek Habersack <mhabersack@novell.com>
* SessionStateModule.cs: use Request.FilePath instead of
Request.BaseVirtualDirectory to retrieve the cookie-less session
identifier. Fixes bug #397418
2008-06-04 Marek Habersack <mhabersack@novell.com>
* SessionStateModule.cs: set the application modifier path to bare
session id.
2008-05-30 Marek Habersack <mhabersack@novell.com>
* SessionStateModule.cs: do not use synthetized event accessors
(to avoid locks).
2008-04-24 Marek Habersack <mhabersack@novell.com>
* SessionStateModule.cs: reset the storage data item timeout to
the HttpApplication.Session.Timeout value after the Session_Start
event is fired. Fixes bug #382644
2007-11-05 Marek Habersack <mhabersack@novell.com>
* SessionStateModule.cs: use TimeSpan.TotalMinutes wherever a
session timeout is required, so that sessions do not expire
prematurely. Fixes bug #339026. Patch from Adriaan van Kekem
<adriaanvk@gmail.com>, thanks!
2007-10-17 Marek Habersack <mhabersack@novell.com>
* SessionInProcHandler.cs: in certain situations the 'item'
parameter passed to SetAndReleaseItemExclusive may be null. The
issue was reported in bug #333898, but the reporter cannot provide
a test case that triggers the issue. Added work around the problem
in the way that should have the least impact on the rest of the
code. If 'item' is null, then the new session item is created
without the items and staticItems collections - they will be
initialized to defaults when retrieving the session item. This is
not a correct fix, but since there is no test case this is the
best what can be done right now.
2007-10-15 Juraj Skripsky <js@hotfeet.ch>
* SessionStateModule.cs (Init): Use HttpApplication.LoadType,
don't swallow TypeLoadException.
2007-10-15 Marek Habersack <mhabersack@novell.com>
* SessionStateServerHandler.cs: adjust order of field
initialization.
2007-09-18 Marek Habersack <mhabersack@novell.com>
* SessionIDManager.cs: preserve the query part of the url when
redirecting with cookieless sessions active. Fixes bug #318790
2007-09-07 Marek Habersack <mhabersack@novell.com>
* SessionInProcHandler.cs: properly clone the
ApplicationState.SessionObjects at the start of the request and
use the copy when creating new storage items. That way session
scope static objects are valid within a single session only. Fixes
bug #82709
2007-08-14 Marek Habersack <mhabersack@novell.com>
* SessionStateServerHandler.cs: remove unused field.
2007-07-31 Marek Habersack <mhabersack@novell.com>
* SessionInProcHandler.cs: initialize the static session objects
collection from the application state instead of using
SessionStateUtility.GetSessionStaticObjects. Fixes bug #82193
* SessionStateServerHandler.cs: as above
2007-07-30 Igor Zelmanovich <igorz@mainsoft.com>
* SessionStateModule.cs:
ensure release (save) session state at OnEndRequest.
2007-06-20 Marek Habersack <mhabersack@novell.com>
* SessionInProcHandler.cs: use HttpRuntime.InternalCache to keep
the internal entries.
* SessionStateModule.cs: if session is abandoned and the handler
supports expiration, disable the handler's session expiration
callback and call SessionStateUtility.RaiseSessionEnd
directly. Fixes bug #81853.
2007-04-30 Marek Habersack <mhabersack@novell.com>
* SessionInProcHandler.cs: do not end session when setting and
releasing item in mid-session. Fixes bugs #81440, #81140 and
#80723
2007-04-18 Marek Habersack <mhabersack@novell.com>
* SessionInProcHandler.cs: added protection against raising early
session end event when resetting item timeout. Fixes bug #81140
2007-03-12 Konstantin Triger <kostat@mainsoft.com>
* SessionStateModule.cs: TARGET_J2EE: support only J2EE sessions.
2007-03-06 Marek Habersack <mhabersack@novell.com>
* SessionInProcHandler.cs: gracefully handle different value types
in the session removal handler.
* SessionStateModule.cs: create an empty container if session data
is null. Fixes bug 80682
2007-02-19 Konstantin Triger <kostat@mainsoft.com>
* SessionStateModule.cs: call Session_End callback only if the handler
does not support expiration.
2007-01-20 Miguel de Icaza <miguel@novell.com>
* SessionStateModule.cs: Removed unused variables.
2007-01-07 Konstantin Triger <kostat@mainsoft.com>
* SessionStateModule.cs: Implemented raising of Session_OnEnd event,
refactoring.
2006-12-27 Konstantin Triger <kostat@mainsoft.com>
* SessionIDManager.cs: Pass config to SessionStateModule.IsCookieLess.
* SessionStateStoreData.cs: fix constructor signature.
* SessionInProcHandler.cs, SessionStateServerHandler.cs: ensure has a default
constructor to make instantiating same as for custom provider.
* SessionStateModule.cs: support custom providers.
2006-12-20 Marek Habersack <grendello@gmail.com>
* SessionStateServerHandler.cs:
implemented for the 2.0 model.
* SessionStateUtility.cs:
implemented.
* SessionStateStoreProviderBase.cs:
implemented.
* SessionInProcHandler.cs:
reimplemented for the 2.0 model.
* SessionIDManager.cs: implemented.
* SessionStateModule.cs: copied the
file to new location and implemented the 2.0 model.
* SessionSQLServerHandler.cs:
created. Implementation not done yet.
* HttpSessionStateContainer.cs: copied
the file to new location and implemented the 2.0 model.
* StateServerItem.cs: implementation
for the 2.0 model.
* HttpSessionState.cs: reimplemented
for the 2.0 model.
* RemoteStateServer.cs: copied the
file to new location and added new code for the 2.0 model.
* SessionStateItemCollection.cs:
implemented.
* SessionStateActions.cs: moved the
file to new location and added the None member.
* ISessionIDManager.cs: moved the file
to new location.
* SessionStateItemExpireCallback.cs:
moved the file to new location.
* IHttpSessionState.cs: moved the file
to new location.
* SessionStateStoreData.cs: moved the
file to new location and modified for the 2.0 model.
* ISessionStateItemCollection.cs:
moved the file to new location.

View File

@@ -0,0 +1,171 @@
//
// System.Web.SessionState.HttpSessionState
//
// Authors:
// Gonzalo Paniagua Javier (gonzalo@ximian.com)
//
// (C) 2002,2003 Ximian, Inc (http://www.ximian.com)
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System.Collections;
using System.Collections.Specialized;
using System.Security.Permissions;
using System.Web;
namespace System.Web.SessionState {
// CAS - no InheritanceDemand here as the class is sealed
[AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public sealed class HttpSessionState : ICollection, IEnumerable
{
IHttpSessionState container;
internal HttpSessionState (IHttpSessionState container)
{
this.container = container;
}
internal IHttpSessionState Container {
get { return container; }
}
public int CodePage {
get { return container.CodePage; }
set { container.CodePage = value; }
}
public HttpSessionState Contents {
get { return this; }
}
public HttpCookieMode CookieMode {
get {
if (IsCookieless)
return HttpCookieMode.UseUri;
else
return HttpCookieMode.UseCookies;
}
}
public int Count {
get { return container.Count; }
}
public bool IsCookieless {
get { return container.IsCookieless; }
}
public bool IsNewSession {
get { return container.IsNewSession; }
}
public bool IsReadOnly {
get { return container.IsReadOnly; }
}
public bool IsSynchronized {
get { return container.IsSynchronized; }
}
public object this [string key] {
get { return container [key]; }
set { container [key] = value; }
}
public object this [int index] {
get { return container [index]; }
set { container [index] = value; }
}
public NameObjectCollectionBase.KeysCollection Keys {
get { return container.Keys; }
}
public int LCID {
get { return container.LCID; }
set { container.LCID = value; }
}
public SessionStateMode Mode {
get { return container.Mode; }
}
public string SessionID {
get { return container.SessionID; }
}
public HttpStaticObjectsCollection StaticObjects {
get { return container.StaticObjects; }
}
public object SyncRoot {
get { return container.SyncRoot; }
}
public int Timeout {
get { return container.Timeout; }
set { container.Timeout = value; }
}
public void Abandon ()
{
container.Abandon ();
}
public void Add (string name, object value)
{
container.Add (name, value);
}
public void Clear ()
{
container.Clear ();
}
public void CopyTo (Array array, int index)
{
container.CopyTo (array, index);
}
public IEnumerator GetEnumerator ()
{
return container.GetEnumerator ();
}
public void Remove (string name)
{
container.Remove (name);
}
public void RemoveAll ()
{
container.Clear ();
}
public void RemoveAt (int index)
{
container.RemoveAt (index);
}
}
}
#endif

View File

@@ -0,0 +1,254 @@
//
// System.Web.Compilation.SessionStateItemCollection
//
// Authors:
// Gonzalo Paniagua Javier (gonzalo@ximian.com)
// Marek Habersack (grendello@gmail.com)
//
// (C) 2006 Marek Habersack
// (C) 2002,2003 Ximian, Inc (http://www.ximian.com)
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Globalization;
using System.Text;
using System.Threading;
using System.Web.Util;
namespace System.Web.SessionState
{
public class HttpSessionStateContainer : IHttpSessionState
{
string id;
HttpStaticObjectsCollection staticObjects;
int timeout;
bool newSession;
bool isCookieless;
SessionStateMode mode;
bool isReadOnly;
internal bool abandoned;
ISessionStateItemCollection sessionItems;
HttpCookieMode cookieMode;
public HttpSessionStateContainer (string id,
ISessionStateItemCollection sessionItems,
HttpStaticObjectsCollection staticObjects,
int timeout,
bool newSession,
HttpCookieMode cookieMode,
SessionStateMode mode,
bool isReadonly)
{
if (id == null)
throw new ArgumentNullException ("id");
this.sessionItems = sessionItems;
this.id = id;
this.staticObjects = staticObjects;
this.timeout = timeout;
this.newSession = newSession;
this.cookieMode = cookieMode;
this.mode = mode;
this.isReadOnly = isReadonly;
this.isCookieless = cookieMode == HttpCookieMode.UseUri;
}
public int CodePage {
get {
HttpContext current = HttpContext.Current;
if (current == null)
return Encoding.Default.CodePage;
return current.Response.ContentEncoding.CodePage;
}
set {
HttpContext current = HttpContext.Current;
if (current != null)
current.Response.ContentEncoding = Encoding.GetEncoding (value);
}
}
public HttpCookieMode CookieMode {
get { return cookieMode; }
}
public int Count {
get {
if (sessionItems != null)
return sessionItems.Count;
return 0;
}
}
public bool IsAbandoned {
get { return abandoned; }
}
public bool IsCookieless {
get { return isCookieless; }
}
public bool IsNewSession {
get { return newSession; }
}
public bool IsReadOnly {
get { return isReadOnly; }
}
public bool IsSynchronized {
get { return false; }
}
object IHttpSessionState.this [int index] {
get {
if (sessionItems == null || sessionItems.Count == 0)
return null;
return sessionItems [index];
}
set {
if (sessionItems != null)
sessionItems [index] = value;
}
}
object IHttpSessionState.this [string name] {
get {
if (sessionItems == null || sessionItems.Count == 0)
return null;
return sessionItems [name];
}
set {
if (sessionItems != null)
sessionItems [name] = value;
}
}
NameObjectCollectionBase.KeysCollection IHttpSessionState.Keys {
get {
if (sessionItems != null)
return sessionItems.Keys;
return null;
}
}
public int LCID {
get { return Thread.CurrentThread.CurrentCulture.LCID; }
set { Thread.CurrentThread.CurrentCulture = new CultureInfo(value); }
}
public SessionStateMode Mode {
get { return mode; }
}
public string SessionID {
get { return id; }
}
public HttpStaticObjectsCollection StaticObjects {
get { return staticObjects; }
}
public Object SyncRoot {
get { return this; }
}
public int Timeout {
get { return timeout; }
set {
if (value < 1)
throw new ArgumentException ("The argument to SetTimeout must be greater than 0.");
timeout = value;
}
}
internal void SetNewSession (bool value)
{
newSession = value;
}
public void Abandon ()
{
abandoned = true;
}
public void Add (string name, Object value)
{
if (sessionItems == null)
return;
sessionItems [name] = value;
}
public void Clear ()
{
if (sessionItems == null)
return;
sessionItems.Clear ();
}
public void CopyTo (Array array, int index)
{
if (sessionItems == null)
return;
NameObjectCollectionBase.KeysCollection all = sessionItems.Keys;
for (int i = 0; i < all.Count; i++)
array.SetValue (all.Get(i), i + index);
}
public IEnumerator GetEnumerator ()
{
if (sessionItems == null)
return null;
return sessionItems.GetEnumerator ();
}
public void Remove (string name)
{
if (sessionItems == null)
return;
sessionItems.Remove (name);
}
public void RemoveAll ()
{
if (sessionItems == null)
return;
sessionItems.Clear ();
}
public void RemoveAt (int index)
{
if (sessionItems == null)
return;
sessionItems.RemoveAt (index);
}
}
}
#endif

View File

@@ -0,0 +1,69 @@
//
// System.Web.SessionState.IReadOnlySessionState
//
// Authors:
// Sanjay Gupta (gsanjay@novell.com)
//
// (C) 2004 Novell, Inc (http://www.novell.com)
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System.Collections;
using System.Collections.Specialized;
namespace System.Web.SessionState {
public interface IHttpSessionState
{
///methods
void Abandon ();
void Add (string itemName, object itemValue);
void Clear ();
void CopyTo (Array sessionValues, int index);
IEnumerator GetEnumerator ();
void Remove (string itemName);
void RemoveAll ();
void RemoveAt (int index);
///properties
int CodePage { get; set; }
HttpCookieMode CookieMode { get; }
int Count { get; }
bool IsCookieless { get; }
bool IsNewSession { get; }
bool IsReadOnly { get; }
bool IsSynchronized { get; }
object this [int index] { get; set; }
object this [string name] { get; set;}
NameObjectCollectionBase.KeysCollection Keys { get; }
int LCID { get; set; }
SessionStateMode Mode { get; }
string SessionID { get; }
HttpStaticObjectsCollection StaticObjects { get; }
object SyncRoot { get; }
int Timeout { get; set; }
}
}
#endif

View File

@@ -0,0 +1,36 @@
//
// System.Web.SessionState.IReadOnlySessionState
//
// Authors:
// Gonzalo Paniagua Javier (gonzalo@ximian.com)
//
// (C) 2002 Ximian, Inc (http://www.ximian.com)
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace System.Web.SessionState {
public interface IReadOnlySessionState : IRequiresSessionState
{
}
}

View File

@@ -0,0 +1,36 @@
//
// System.Web.SessionState.IRequiresSessionState
//
// Authors:
// Gonzalo Paniagua Javier (gonzalo@ximian.com)
//
// (C) 2002 Ximian, Inc (http://www.ximian.com)
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace System.Web.SessionState {
public interface IRequiresSessionState
{
}
}

View File

@@ -0,0 +1,50 @@
//
// System.Web.SessionState.ISessionIDManager
//
// Authors:
// Sanjay Gupta (gsanjay@novell.com)
//
// (C) 2004 Novell, Inc (http://www.novell.com)
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System;
using System.Web;
namespace System.Web.SessionState {
public interface ISessionIDManager
{
///methods
string CreateSessionID (HttpContext context);
string GetSessionID (HttpContext context);
void Initialize ();
bool InitializeRequest (HttpContext context, bool suppressAutoDetectRedirect, out bool supportSessionIDReissue);
void RemoveSessionID (HttpContext context);
void SaveSessionID (HttpContext context, string sessionID, out bool isRedirected, out bool isCookieAdded);
bool Validate (string id);
}
}
#endif

View File

@@ -0,0 +1,51 @@
//
// System.Web.SessionState.ISessionStateItemCollection
//
// Authors:
// Sanjay Gupta (gsanjay@novell.com)
//
// Copyright (c) 2004-2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System.Collections;
using System.Collections.Specialized;
namespace System.Web.SessionState {
public interface ISessionStateItemCollection : ICollection, IEnumerable
{
///methods
void Clear ();
void Remove (string itemName);
void RemoveAt (int index);
///properties
bool Dirty { get; set; }
object this [int index] { get; set; }
object this [string name] { get; set;}
NameObjectCollectionBase.KeysCollection Keys { get; }
}
}
#endif

View File

@@ -0,0 +1,69 @@
//
// System.Web.SessionState.IStateRuntime.cs
//
// Author:
// Andreas Nahr (ClassDevelopment@A-SoftTech.com)
//
// (C) 2003 Andreas Nahr
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Runtime.InteropServices;
namespace System.Web.SessionState
{
[Guid ("7297744b-e188-40bf-b7e9-56698d25cf44")]
[InterfaceType (ComInterfaceType.InterfaceIsIUnknown)]
#if NET_2_0
[ComImportAttribute]
#endif
public interface IStateRuntime
{
void ProcessRequest (
[In, MarshalAs(UnmanagedType.SysInt)] IntPtr tracker,
[In, MarshalAs(UnmanagedType.I4)] int verb,
[In, MarshalAs(UnmanagedType.LPWStr)] string uri,
[In, MarshalAs(UnmanagedType.I4)] int exclusive,
[In, MarshalAs(UnmanagedType.I4)] int timeout,
[In, MarshalAs(UnmanagedType.I4)] int lockCookieExists,
[In, MarshalAs(UnmanagedType.I4)] int lockCookie,
[In, MarshalAs(UnmanagedType.I4)] int contentLength,
[In, MarshalAs(UnmanagedType.SysInt)] IntPtr content);
#if NET_2_0
void ProcessRequest (
[In, MarshalAs(UnmanagedType.SysInt)] IntPtr tracker,
[In, MarshalAs(UnmanagedType.I4)] int verb,
[In, MarshalAs(UnmanagedType.LPWStr)] string uri,
[In, MarshalAs(UnmanagedType.I4)] int exclusive,
[In, MarshalAs(UnmanagedType.I4)] int extraFlags,
[In, MarshalAs(UnmanagedType.I4)] int timeout,
[In, MarshalAs(UnmanagedType.I4)] int lockCookieExists,
[In, MarshalAs(UnmanagedType.I4)] int lockCookie,
[In, MarshalAs(UnmanagedType.I4)] int contentLength,
[In, MarshalAs(UnmanagedType.SysInt)] IntPtr content);
#endif
void StopProcessing ();
}
}

View File

@@ -0,0 +1,192 @@
//
// System.Web.SessionState.RemoteStateServer
//
// Author(s):
// Jackson Harper (jackson@ximian.com)
// Gonzalo Paniagua (gonzalo@ximian.com)
// Marek Habersack (grendello@gmail.com)
//
// (C) 2003-2006 Novell, Inc (http://www.novell.com)
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System;
using System.Threading;
using System.Web.Caching;
namespace System.Web.SessionState {
class LockableStateServerItem
{
public StateServerItem item;
public ReaderWriterLock rwlock;
public LockableStateServerItem (StateServerItem item)
{
this.item = item;
this.rwlock = new ReaderWriterLock ();
}
}
internal class RemoteStateServer : MarshalByRefObject {
const Int32 lockAcquireTimeout = 30000;
Cache cache;
internal RemoteStateServer ()
{
cache = new Cache ();
}
void Insert (string id, LockableStateServerItem item)
{
cache.Insert (id, item, null, Cache.NoAbsoluteExpiration, new TimeSpan (0, item.item.Timeout, 0));
}
LockableStateServerItem Retrieve (string id)
{
return cache [id] as LockableStateServerItem;
}
internal void CreateUninitializedItem (string id, int timeout)
{
StateServerItem item = new StateServerItem (timeout);
item.Action = SessionStateActions.InitializeItem;
LockableStateServerItem cacheItem = new LockableStateServerItem (item);
Insert (id, cacheItem);
}
internal StateServerItem GetItem (string id,
out bool locked,
out TimeSpan lockAge,
out object lockId,
out SessionStateActions actions,
bool exclusive)
{
locked = false;
lockAge = TimeSpan.MinValue;
lockId = Int32.MinValue;
actions = SessionStateActions.None;
LockableStateServerItem item = Retrieve (id);
if (item == null || item.item.IsAbandoned ())
return null;
try {
item.rwlock.AcquireReaderLock (lockAcquireTimeout);
if (item.item.Locked) {
locked = true;
lockAge = DateTime.UtcNow.Subtract (item.item.LockedTime);
lockId = item.item.LockId;
return null;
}
item.rwlock.ReleaseReaderLock ();
if (exclusive) {
item.rwlock.AcquireWriterLock (lockAcquireTimeout);
item.item.Locked = true;
item.item.LockedTime = DateTime.UtcNow;
item.item.LockId++;
lockId = item.item.LockId;
}
} catch {
throw;
} finally {
if (item.rwlock.IsReaderLockHeld)
item.rwlock.ReleaseReaderLock ();
if (item.rwlock.IsWriterLockHeld)
item.rwlock.ReleaseWriterLock ();
}
actions = item.item.Action;
return item.item;
}
internal void Remove (string id, object lockid)
{
cache.Remove (id);
}
internal void ResetItemTimeout (string id)
{
LockableStateServerItem item = Retrieve (id);
if (item == null)
return;
item.item.Touch ();
}
internal void ReleaseItemExclusive (string id, object lockId)
{
LockableStateServerItem item = Retrieve (id);
if (item == null || item.item.LockId != (Int32)lockId)
return;
try {
item.rwlock.AcquireWriterLock (lockAcquireTimeout);
item.item.Locked = false;
} catch {
throw;
} finally {
if (item.rwlock.IsWriterLockHeld)
item.rwlock.ReleaseWriterLock ();
}
}
internal void SetAndReleaseItemExclusive (string id, byte [] collection_data, byte [] sobjs_data,
object lockId, int timeout, bool newItem)
{
LockableStateServerItem item = Retrieve (id);
bool fresh = false;
if (newItem || item == null) {
item = new LockableStateServerItem (new StateServerItem (collection_data, sobjs_data, timeout));
item.item.LockId = (Int32)lockId;
fresh = true;
} else {
if (item.item.LockId != (Int32)lockId)
return;
Remove (id, lockId);
}
try {
item.rwlock.AcquireWriterLock (lockAcquireTimeout);
item.item.Locked = false;
if (!fresh) {
item.item.CollectionData = collection_data;
item.item.StaticObjectsData = sobjs_data;
}
Insert (id, item);
} catch {
throw;
} finally {
if (item.rwlock.IsWriterLockHeld)
item.rwlock.ReleaseWriterLock ();
}
}
public override object InitializeLifetimeService ()
{
return null; // just in case...
}
}
}
#endif

View File

@@ -0,0 +1,138 @@
//
// System.Web.Compilation.SessionStateItemCollection
//
// Authors:
// Marek Habersack (grendello@gmail.com)
//
// (C) 2006 Marek Habersack
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System.Web;
using System.Web.Configuration;
using System.Web.Util;
namespace System.Web.SessionState
{
public class SessionIDManager : ISessionIDManager
{
SessionStateSection config;
public SessionIDManager ()
{
}
public static int SessionIDMaxLength {
get { return 80; }
}
// Todo: find use for the context parameter?
public virtual string CreateSessionID (HttpContext context)
{
return SessionId.Create ();
}
public virtual string Decode (string id)
{
return HttpUtility.UrlDecode (id);
}
public virtual string Encode (string id)
{
return HttpUtility.UrlEncode (id);
}
public string GetSessionID (HttpContext context)
{
string ret = null;
if (SessionStateModule.IsCookieLess (context, config)) {
string tmp = context.Request.Headers [SessionStateModule.HeaderName];
if (tmp != null)
ret = Decode (tmp);
} else {
HttpCookie cookie = context.Request.Cookies [config.CookieName];
if (cookie != null)
ret = Decode (cookie.Value);
}
if (ret != null && ret.Length > SessionIDMaxLength)
throw new HttpException ("The length of the session-identifier value retrieved from the HTTP request exceeds the SessionIDMaxLength value.");
if (!Validate (ret))
throw new HttpException ("Invalid session ID");
return ret;
}
public void Initialize ()
{
config = WebConfigurationManager.GetSection ("system.web/sessionState") as SessionStateSection;
}
public bool InitializeRequest (HttpContext context, bool suppressAutoDetectRedirect, out bool supportSessionIDReissue)
{
// TODO: Implement AutoDetect handling
if (config.CookieLess) {
supportSessionIDReissue = true;
return false;
} else {
supportSessionIDReissue = false;
return false;
}
}
public void RemoveSessionID (HttpContext context)
{
context.Response.Cookies.Remove(config.CookieName);
}
// TODO: add code to check whether the response has already been sent
public void SaveSessionID (HttpContext context, string id, out bool redirected, out bool cookieAdded)
{
if (!Validate (id))
throw new HttpException ("Invalid session ID");
HttpRequest request = context.Request;
if (!SessionStateModule.IsCookieLess (context, config)) {
HttpCookie cookie = new HttpCookie (config.CookieName, id);
cookie.Path = request.ApplicationPath;
context.Response.AppendCookie (cookie);
cookieAdded = true;
redirected = false;
} else {
request.SetHeader (SessionStateModule.HeaderName, id);
cookieAdded = false;
redirected = true;
UriBuilder newUri = new UriBuilder (request.Url);
newUri.Path = UrlUtils.InsertSessionId (id, request.FilePath);
context.Response.Redirect (newUri.Uri.PathAndQuery, false);
}
}
public virtual bool Validate (string id)
{
return true;
}
}
}
#endif

View File

@@ -0,0 +1,67 @@
//
// System.Web.SessionState.SessionId
//
// Author(s):
// Jackson Harper (jackson@ximian.com)
//
// Copyright (C) 2003,2006 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.Text;
using System.Security.Cryptography;
using System.Web.Util;
namespace System.Web.SessionState {
internal class SessionId {
internal const int IdLength = 24;
const int half_len = IdLength / 2;
static RandomNumberGenerator rng = RandomNumberGenerator.Create ();
internal static string Create ()
{
byte[] key = new byte [half_len];
lock (rng) {
rng.GetBytes (key);
}
return MachineKeySectionUtils.GetHexString (key);
}
#if !NET_2_0
internal static string Lookup (HttpRequest request, bool cookieless)
{
if (cookieless)
return (string) request.Headers [SessionStateModule.HeaderName];
HttpCookie cookie = request.Cookies [SessionStateModule.CookieName];
if (cookie == null)
return null;
return cookie.Value;
}
#endif
}
}

View File

@@ -0,0 +1,461 @@
//
// System.Web.SessionState.SessionInProcHandler
//
// Authors:
// Marek Habersack <grendello@gmail.com>
//
// (C) 2006 Marek Habersack
// (C) 2010 Novell, Inc (http://novell.com/)
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System;
using System.IO;
using System.Collections;
using System.Collections.Specialized;
using System.Configuration.Provider;
using System.Web.Caching;
using System.Web.Configuration;
using System.Threading;
namespace System.Web.SessionState
{
internal sealed class InProcSessionItem
{
public bool locked;
public bool cookieless;
public ISessionStateItemCollection items;
public DateTime lockedTime;
public DateTime expiresAt;
public ReaderWriterLockSlim rwlock;
public Int32 lockId;
public int timeout;
public bool resettingTimeout;
public HttpStaticObjectsCollection staticItems;
internal InProcSessionItem ()
{
this.locked = false;
this.cookieless = false;
this.items = null;
this.staticItems = null;
this.lockedTime = DateTime.MinValue;
this.expiresAt = DateTime.MinValue;
this.rwlock = new ReaderWriterLockSlim ();
this.lockId = Int32.MinValue;
this.timeout = 0;
this.resettingTimeout = false;
}
public void Dispose ()
{
if (rwlock != null) {
rwlock.Dispose ();
rwlock = null;
}
staticItems = null;
if (items != null)
items.Clear ();
items = null;
}
~InProcSessionItem ()
{
Dispose ();
}
}
internal class SessionInProcHandler : SessionStateStoreProviderBase
{
const string CachePrefix = "@@@InProc@";
const int CachePrefixLength = 10;
const Int32 lockAcquireTimeout = 30000;
CacheItemRemovedCallback removedCB;
//NameValueCollection privateConfig;
SessionStateItemExpireCallback expireCallback;
HttpStaticObjectsCollection staticObjects;
public override SessionStateStoreData CreateNewStoreData (HttpContext context, int timeout)
{
return new SessionStateStoreData (new SessionStateItemCollection (),
staticObjects, timeout);
}
void InsertSessionItem (InProcSessionItem item, int timeout, string id)
{
if (item == null || String.IsNullOrEmpty (id))
return;
HttpRuntime.InternalCache.Insert (id,
item,
null,
Cache.NoAbsoluteExpiration,
TimeSpan.FromMinutes (timeout),
CacheItemPriority.AboveNormal,
removedCB);
}
void UpdateSessionItemTimeout (int timeout, string id)
{
if (String.IsNullOrEmpty (id))
return;
HttpRuntime.InternalCache.SetItemTimeout (id, Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes (timeout), true);
}
public override void CreateUninitializedItem (HttpContext context, string id, int timeout)
{
EnsureGoodId (id, true);
InProcSessionItem item = new InProcSessionItem ();
item.expiresAt = DateTime.UtcNow.AddMinutes (timeout);
item.timeout = timeout;
InsertSessionItem (item, timeout, CachePrefix + id);
}
public override void Dispose ()
{
}
public override void EndRequest (HttpContext context)
{
if (staticObjects != null) {
staticObjects.GetObjects ().Clear ();
staticObjects = null;
}
}
SessionStateStoreData GetItemInternal (HttpContext context,
string id,
out bool locked,
out TimeSpan lockAge,
out object lockId,
out SessionStateActions actions,
bool exclusive)
{
locked = false;
lockAge = TimeSpan.MinValue;
lockId = Int32.MinValue;
actions = SessionStateActions.None;
if (id == null)
return null;
Cache cache = HttpRuntime.InternalCache;
string CacheId = CachePrefix + id;
InProcSessionItem item = cache [CacheId] as InProcSessionItem;
if (item == null)
return null;
bool readLocked = false, writeLocked = false;
try {
if (item.rwlock.TryEnterUpgradeableReadLock (lockAcquireTimeout))
readLocked = true;
else
throw new ApplicationException ("Failed to acquire lock");
if (item.locked) {
locked = true;
lockAge = DateTime.UtcNow.Subtract (item.lockedTime);
lockId = item.lockId;
return null;
}
if (exclusive) {
if (item.rwlock.TryEnterWriteLock (lockAcquireTimeout))
writeLocked = true;
else
throw new ApplicationException ("Failed to acquire lock");
item.locked = true;
item.lockedTime = DateTime.UtcNow;
item.lockId++;
lockId = item.lockId;
}
if (item.items == null) {
actions = SessionStateActions.InitializeItem;
item.items = new SessionStateItemCollection ();
}
if (item.staticItems == null)
item.staticItems = staticObjects;
return new SessionStateStoreData (item.items,
item.staticItems,
item.timeout);
} catch {
// we want such errors to be passed to the application.
throw;
} finally {
if (writeLocked)
item.rwlock.ExitWriteLock ();
if (readLocked)
item.rwlock.ExitUpgradeableReadLock ();
}
}
public override SessionStateStoreData GetItem (HttpContext context,
string id,
out bool locked,
out TimeSpan lockAge,
out object lockId,
out SessionStateActions actions)
{
EnsureGoodId (id, false);
return GetItemInternal (context, id, out locked, out lockAge, out lockId, out actions, false);
}
public override SessionStateStoreData GetItemExclusive (HttpContext context,
string id,
out bool locked,
out TimeSpan lockAge,
out object lockId,
out SessionStateActions actions)
{
EnsureGoodId (id, false);
return GetItemInternal (context, id, out locked, out lockAge, out lockId, out actions, true);
}
public override void Initialize (string name, NameValueCollection config)
{
if (String.IsNullOrEmpty (name))
name = "Session InProc handler";
removedCB = new CacheItemRemovedCallback (OnSessionRemoved);
//privateConfig = config;
base.Initialize (name, config);
}
public override void InitializeRequest (HttpContext context)
{
staticObjects = HttpApplicationFactory.ApplicationState.SessionObjects.Clone ();
}
public override void ReleaseItemExclusive (HttpContext context,
string id,
object lockId)
{
EnsureGoodId (id, true);
string CacheId = CachePrefix + id;
InProcSessionItem item = HttpRuntime.InternalCache [CacheId] as InProcSessionItem;
if (item == null || lockId == null || lockId.GetType() != typeof(Int32) || item.lockId != (Int32)lockId)
return;
bool locked = false;
ReaderWriterLockSlim itemLock = null;
try {
itemLock = item.rwlock;
if (itemLock != null && itemLock.TryEnterWriteLock (lockAcquireTimeout))
locked = true;
else
throw new ApplicationException ("Failed to acquire lock");
item.locked = false;
} catch {
throw;
} finally {
if (locked && itemLock != null)
itemLock.ExitWriteLock ();
}
}
public override void RemoveItem (HttpContext context,
string id,
object lockId,
SessionStateStoreData item)
{
EnsureGoodId (id, true);
string CacheId = CachePrefix + id;
Cache cache = HttpRuntime.InternalCache;
InProcSessionItem inProcItem = cache [CacheId] as InProcSessionItem;
if (inProcItem == null || lockId == null || lockId.GetType() != typeof(Int32) || inProcItem.lockId != (Int32)lockId)
return;
bool locked = false;
ReaderWriterLockSlim itemLock = null;
try {
itemLock = inProcItem.rwlock;
if (itemLock != null && itemLock.TryEnterWriteLock (lockAcquireTimeout))
locked = true;
else
throw new ApplicationException ("Failed to acquire lock after");
cache.Remove (CacheId);
} catch {
throw;
} finally {
if (locked)
itemLock.ExitWriteLock ();
}
}
public override void ResetItemTimeout (HttpContext context, string id)
{
EnsureGoodId (id, true);
string CacheId = CachePrefix + id;
Cache cache = HttpRuntime.InternalCache;
InProcSessionItem item = cache [CacheId] as InProcSessionItem;
if (item == null)
return;
bool locked = false;
ReaderWriterLockSlim itemLock = null;
try {
itemLock = item.rwlock;
if (itemLock != null && itemLock.TryEnterWriteLock (lockAcquireTimeout))
locked = true;
else
throw new ApplicationException ("Failed to acquire lock after");
item.resettingTimeout = true;
UpdateSessionItemTimeout (item.timeout, CacheId);
} catch {
throw;
} finally {
if (locked && itemLock != null)
itemLock.ExitWriteLock ();
}
}
/* In certain situations the 'item' parameter passed to SetAndReleaseItemExclusive
may be null. The issue was reported in bug #333898, but the reporter cannot
provide a test case that triggers the issue. Added work around the problem
in the way that should have the least impact on the rest of the code. If 'item'
is null, then the new session item is created without the items and staticItems
collections - they will be initialized to defaults when retrieving the session
item. This is not a correct fix, but since there is no test case this is the best
what can be done right now.
*/
public override void SetAndReleaseItemExclusive (HttpContext context,
string id,
SessionStateStoreData item,
object lockId,
bool newItem)
{
EnsureGoodId (id, true);
string CacheId = CachePrefix + id;
Cache cache = HttpRuntime.InternalCache;
InProcSessionItem inProcItem = cache [CacheId] as InProcSessionItem;
ISessionStateItemCollection itemItems = null;
int itemTimeout = 20;
HttpStaticObjectsCollection itemStaticItems = null;
if (item != null) {
itemItems = item.Items;
itemTimeout = item.Timeout;
itemStaticItems = item.StaticObjects;
}
if (newItem || inProcItem == null) {
inProcItem = new InProcSessionItem ();
inProcItem.timeout = itemTimeout;
inProcItem.expiresAt = DateTime.UtcNow.AddMinutes (itemTimeout);
if (lockId.GetType() == typeof(Int32))
inProcItem.lockId = (Int32)lockId;
} else {
if (lockId == null || lockId.GetType() != typeof(Int32) || inProcItem.lockId != (Int32)lockId)
return;
inProcItem.resettingTimeout = true;
cache.Remove (CacheId);
}
bool locked = false;
ReaderWriterLockSlim itemLock = null;
try {
itemLock = inProcItem.rwlock;
if (itemLock != null && itemLock.TryEnterWriteLock (lockAcquireTimeout))
locked = true;
else if (itemLock != null)
throw new ApplicationException ("Failed to acquire lock");
if (inProcItem.resettingTimeout)
UpdateSessionItemTimeout (itemTimeout, CacheId);
else {
inProcItem.locked = false;
inProcItem.items = itemItems;
inProcItem.staticItems = itemStaticItems;
InsertSessionItem (inProcItem, itemTimeout, CacheId);
}
} catch {
throw;
} finally {
if (locked && itemLock != null)
itemLock.ExitWriteLock ();
}
}
public override bool SetItemExpireCallback (SessionStateItemExpireCallback expireCallback)
{
this.expireCallback = expireCallback;
return true;
}
void EnsureGoodId (string id, bool throwOnNull)
{
if (id == null)
if (throwOnNull)
throw new HttpException ("Session ID is invalid");
else
return;
if (id.Length > SessionIDManager.SessionIDMaxLength)
throw new HttpException ("Session ID too long");
}
void OnSessionRemoved (string key, object value, CacheItemRemovedReason reason)
{
if (expireCallback != null) {
if (key.StartsWith (CachePrefix, StringComparison.OrdinalIgnoreCase))
key = key.Substring (CachePrefixLength);
if (value is SessionStateStoreData)
expireCallback (key, (SessionStateStoreData)value);
else if (value is InProcSessionItem) {
InProcSessionItem item = (InProcSessionItem)value;
if (item.resettingTimeout) {
item.resettingTimeout = false;
return;
}
expireCallback (key,
new SessionStateStoreData (
item.items,
item.staticItems,
item.timeout));
item.Dispose ();
} else
expireCallback (key, null);
} else if (value is InProcSessionItem) {
InProcSessionItem item = (InProcSessionItem)value;
if (item.resettingTimeout) {
item.resettingTimeout = false;
return;
}
item.Dispose ();
}
}
}
}
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,37 @@
//
// System.Web.SessionState.SessionStateActions.cs
//
// Authors:
// Sanjay Gupta (gsanjay@novell.com)
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
namespace System.Web.SessionState {
public enum SessionStateActions {
None = 0,
InitializeItem = 1
}
}
#endif

View File

@@ -0,0 +1,40 @@
//
//
// Authors:
// Marek Habersack <mhabersack@novell.com>
//
//
// Copyright (C) 2010 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
namespace System.Web.SessionState
{
public enum SessionStateBehavior
{
Default,
Required,
ReadOnly,
Disabled
}
}

View File

@@ -0,0 +1,141 @@
//
// System.Web.Compilation.SessionStateItemCollection
//
// Authors:
// Marek Habersack (grendello@gmail.com)
//
// (C) 2006 Marek Habersack
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Web.Util;
namespace System.Web.SessionState
{
public sealed class SessionStateItemCollection : NameObjectCollectionBase, ISessionStateItemCollection, ICollection, IEnumerable
{
bool is_dirty;
static bool IsMutable (object o)
{
return (o != null && Type.GetTypeCode(o.GetType()) == TypeCode.Object);
}
public SessionStateItemCollection ()
{
}
internal SessionStateItemCollection (int capacity)
: base (capacity)
{
}
public bool Dirty {
get { return is_dirty; }
set { is_dirty = value; }
}
public object this [int index] {
get {
object o = BaseGet (index);
if (IsMutable (o))
is_dirty = true;
return o;
}
set {
BaseSet (index, value);
is_dirty = true;
}
}
public object this [string name] {
get {
object o = BaseGet (name);
if (IsMutable (o))
is_dirty = true;
return o;
}
set {
BaseSet (name, value);
is_dirty = true;
}
}
// Todo: why override this?
public override KeysCollection Keys {
get { return base.Keys; }
}
public void Clear ()
{
if (Count > 0) {
BaseClear ();
is_dirty = true;
}
}
public static SessionStateItemCollection Deserialize (BinaryReader reader)
{
int i = reader.ReadInt32 ();
SessionStateItemCollection ret = new SessionStateItemCollection (i);
for (; i > 0; i--)
ret [reader.ReadString ()] =
System.Web.Util.AltSerialization.Deserialize (reader);
return ret;
}
public void Serialize (BinaryWriter writer) {
writer.Write (Count);
foreach (string key in base.Keys) {
writer.Write (key);
System.Web.Util.AltSerialization.Serialize (writer, BaseGet (key));
}
}
// Todo: why override this?
public override IEnumerator GetEnumerator ()
{
return base.GetEnumerator ();
}
public void Remove (string name)
{
BaseRemove (name);
is_dirty = true;
}
public void RemoveAt (int index)
{
BaseRemoveAt (index);
is_dirty = true;
}
}
}
#endif

View File

@@ -0,0 +1,38 @@
//
// System.Web.SessionState.SessionStateItemExpireCallback
//
// Authors:
// Sanjay Gupta (gsanjay@novell.com)
//
// (C) 2004 Novell, Inc (http://www.novell.com)
//
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
namespace System.Web.SessionState
{
public delegate void SessionStateItemExpireCallback (
string id, SessionStateStoreData item);
}
#endif

View File

@@ -0,0 +1,43 @@
//
// System.Web.SessionState.SessionStateMode
//
// Authors:
// Gonzalo Paniagua Javier (gonzalo@ximian.com)
//
// (C) 2002 Ximian, Inc (http://www.ximian.com)
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
namespace System.Web.SessionState {
public enum SessionStateMode
{
Off = 0,
InProc = 1,
StateServer = 2,
SQLServer = 3,
#if NET_2_0
Custom = 4,
#endif
}
}

View File

@@ -0,0 +1,421 @@
//
// System.Web.SessionState.SesionStateModule
//
// Authors:
// Gonzalo Paniagua Javier (gonzalo@ximian.com)
// Stefan Görling (stefan@gorling.se)
// Jackson Harper (jackson@ximian.com)
// Marek Habersack (grendello@gmail.com)
//
// Copyright (C) 2002-2006 Novell, Inc (http://www.novell.com)
// (C) 2003 Stefan Görling (http://www.gorling.se)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System.Collections.Specialized;
using System.ComponentModel;
using System.Web.Configuration;
using System.Web.Caching;
using System.Web.Util;
using System.Security.Permissions;
using System.Threading;
using System.Configuration;
using System.Diagnostics;
namespace System.Web.SessionState
{
// CAS - no InheritanceDemand here as the class is sealed
[AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public sealed class SessionStateModule : IHttpModule
{
class CallbackState
{
public readonly HttpContext Context;
public readonly AutoResetEvent AutoEvent;
public readonly string SessionId;
public readonly bool IsReadOnly;
public CallbackState (HttpContext context, AutoResetEvent e, string sessionId, bool isReadOnly) {
this.Context = context;
this.AutoEvent = e;
this.SessionId = sessionId;
this.IsReadOnly = isReadOnly;
}
}
internal const string HeaderName = "AspFilterSessionId";
internal const string CookielessFlagName = "_SessionIDManager_IsCookieLess";
static readonly object startEvent = new object ();
static readonly object endEvent = new object ();
SessionStateSection config;
SessionStateStoreProviderBase handler;
ISessionIDManager idManager;
bool supportsExpiration;
HttpApplication app;
// Store state
bool storeLocked;
TimeSpan storeLockAge;
object storeLockId;
SessionStateActions storeSessionAction;
bool storeIsNew;
// Session state
SessionStateStoreData storeData;
HttpSessionStateContainer container;
// config
TimeSpan executionTimeout;
//int executionTimeoutMS;
EventHandlerList events = new EventHandlerList ();
public event EventHandler Start {
add { events.AddHandler (startEvent, value); }
remove { events.RemoveHandler (startEvent, value); }
}
// This event is public, but only Session_[On]End in global.asax will be invoked if present.
public event EventHandler End {
add { events.AddHandler (endEvent, value); }
remove { events.RemoveHandler (endEvent, value); }
}
[SecurityPermission (SecurityAction.Demand, UnmanagedCode = true)]
public SessionStateModule () {
}
public void Dispose () {
app.BeginRequest -= new EventHandler (OnBeginRequest);
app.AcquireRequestState -= new EventHandler (OnAcquireRequestState);
app.ReleaseRequestState -= new EventHandler (OnReleaseRequestState);
app.EndRequest -= new EventHandler (OnEndRequest);
handler.Dispose ();
}
[EnvironmentPermission (SecurityAction.Assert, Read = "MONO_XSP_STATIC_SESSION")]
public void Init (HttpApplication app)
{
config = (SessionStateSection) WebConfigurationManager.GetSection ("system.web/sessionState");
ProviderSettings settings;
switch (config.Mode) {
case SessionStateMode.Custom:
settings = config.Providers [config.CustomProvider];
if (settings == null)
throw new HttpException (String.Format ("Cannot find '{0}' provider.", config.CustomProvider));
break;
case SessionStateMode.Off:
return;
#if TARGET_J2EE
default:
config = new SessionStateSection ();
config.Mode = SessionStateMode.Custom;
config.CustomProvider = "ServletSessionStateStore";
config.SessionIDManagerType = "Mainsoft.Web.SessionState.ServletSessionIDManager";
config.Providers.Add (new ProviderSettings ("ServletSessionStateStore", "Mainsoft.Web.SessionState.ServletSessionStateStoreProvider"));
goto case SessionStateMode.Custom;
#else
case SessionStateMode.InProc:
settings = new ProviderSettings (null, typeof (SessionInProcHandler).AssemblyQualifiedName);
break;
case SessionStateMode.SQLServer:
settings = new ProviderSettings (null, typeof (SessionSQLServerHandler).AssemblyQualifiedName);
break;
case SessionStateMode.StateServer:
settings = new ProviderSettings (null, typeof (SessionStateServerHandler).AssemblyQualifiedName);
break;
default:
throw new NotImplementedException (String.Format ("The mode '{0}' is not implemented.", config.Mode));
#endif
}
handler = (SessionStateStoreProviderBase) ProvidersHelper.InstantiateProvider (settings, typeof (SessionStateStoreProviderBase));
if (String.IsNullOrEmpty(config.SessionIDManagerType)) {
idManager = new SessionIDManager ();
} else {
Type idManagerType = HttpApplication.LoadType (config.SessionIDManagerType, true);
idManager = (ISessionIDManager)Activator.CreateInstance (idManagerType);
}
try {
idManager.Initialize ();
} catch (Exception ex) {
throw new HttpException ("Failed to initialize session ID manager.", ex);
}
supportsExpiration = handler.SetItemExpireCallback (OnSessionExpired);
HttpRuntimeSection runtime = HttpRuntime.Section;
executionTimeout = runtime.ExecutionTimeout;
//executionTimeoutMS = executionTimeout.Milliseconds;
this.app = app;
app.BeginRequest += new EventHandler (OnBeginRequest);
app.AcquireRequestState += new EventHandler (OnAcquireRequestState);
app.ReleaseRequestState += new EventHandler (OnReleaseRequestState);
app.EndRequest += new EventHandler (OnEndRequest);
}
internal static bool IsCookieLess (HttpContext context, SessionStateSection config) {
if (config.Cookieless == HttpCookieMode.UseCookies)
return false;
if (config.Cookieless == HttpCookieMode.UseUri)
return true;
object cookieless = context.Items [CookielessFlagName];
if (cookieless == null)
return false;
return (bool) cookieless;
}
void OnBeginRequest (object o, EventArgs args)
{
HttpApplication application = (HttpApplication) o;
HttpContext context = application.Context;
string file_path = context.Request.FilePath;
string base_path = VirtualPathUtility.GetDirectory (file_path);
string id = UrlUtils.GetSessionId (base_path);
if (id == null)
return;
string new_path = UrlUtils.RemoveSessionId (base_path, file_path);
context.Request.SetFilePath (new_path);
context.Request.SetHeader (HeaderName, id);
context.Response.SetAppPathModifier (id);
}
void OnAcquireRequestState (object o, EventArgs args) {
Trace.WriteLine ("SessionStateModule.OnAcquireRequestState (hash " + this.GetHashCode ().ToString ("x") + ")");
HttpApplication application = (HttpApplication) o;
HttpContext context = application.Context;
if (!(context.Handler is IRequiresSessionState)) {
Trace.WriteLine ("Handler (" + context.Handler + ") does not require session state");
return;
}
bool isReadOnly = (context.Handler is IReadOnlySessionState);
bool supportSessionIDReissue;
if (idManager.InitializeRequest (context, false, out supportSessionIDReissue))
return; // Redirected, will come back here in a while
string sessionId = idManager.GetSessionID (context);
handler.InitializeRequest (context);
storeData = GetStoreData (context, sessionId, isReadOnly);
storeIsNew = false;
if (storeData == null && !storeLocked) {
storeIsNew = true;
sessionId = idManager.CreateSessionID (context);
Trace.WriteLine ("New session ID allocated: " + sessionId);
bool redirected;
bool cookieAdded;
idManager.SaveSessionID (context, sessionId, out redirected, out cookieAdded);
if (redirected) {
if (supportSessionIDReissue)
handler.CreateUninitializedItem (context, sessionId, (int)config.Timeout.TotalMinutes);
context.Response.End ();
return;
}
else
storeData = handler.CreateNewStoreData (context, (int)config.Timeout.TotalMinutes);
}
else if (storeData == null && storeLocked) {
WaitForStoreUnlock (context, sessionId, isReadOnly);
}
else if (storeData != null &&
!storeLocked &&
storeSessionAction == SessionStateActions.InitializeItem &&
IsCookieLess (context, config)) {
storeData = handler.CreateNewStoreData (context, (int)config.Timeout.TotalMinutes);
}
container = CreateContainer (sessionId, storeData, storeIsNew, isReadOnly);
SessionStateUtility.AddHttpSessionStateToContext (app.Context, container);
if (storeIsNew) {
OnSessionStart ();
HttpSessionState hss = app.Session;
if (hss != null)
storeData.Timeout = hss.Timeout;
}
// Whenever a container is abandoned, we temporarily disable the expire call back.
// So in this case we are quite sure we have a brand new container, so we make sure it works again.
supportsExpiration = handler.SetItemExpireCallback (OnSessionExpired);
}
void OnReleaseRequestState (object o, EventArgs args) {
Trace.WriteLine ("SessionStateModule.OnReleaseRequestState (hash " + this.GetHashCode ().ToString ("x") + ")");
HttpApplication application = (HttpApplication) o;
HttpContext context = application.Context;
if (!(context.Handler is IRequiresSessionState))
return;
Trace.WriteLine ("\tsessionId == " + container.SessionID);
Trace.WriteLine ("\trequest path == " + context.Request.FilePath);
Trace.WriteLine ("\tHandler (" + context.Handler + ") requires session state");
try {
if (!container.IsAbandoned) {
Trace.WriteLine ("\tnot abandoned");
if (!container.IsReadOnly) {
Trace.WriteLine ("\tnot read only, storing and releasing");
handler.SetAndReleaseItemExclusive (context, container.SessionID, storeData, storeLockId, storeIsNew);
}
else {
Trace.WriteLine ("\tread only, releasing");
handler.ReleaseItemExclusive (context, container.SessionID, storeLockId);
}
handler.ResetItemTimeout (context, container.SessionID);
}
else {
handler.ReleaseItemExclusive (context, container.SessionID, storeLockId);
handler.RemoveItem (context, container.SessionID, storeLockId, storeData);
if (supportsExpiration)
#if TARGET_J2EE
;
else
#else
// Make sure the expiration handler is not called after we will have raised
// the session end event.
handler.SetItemExpireCallback (null);
#endif
SessionStateUtility.RaiseSessionEnd (container, this, args);
}
SessionStateUtility.RemoveHttpSessionStateFromContext (context);
}
finally {
container = null;
storeData = null;
}
}
void OnEndRequest (object o, EventArgs args) {
if (handler == null)
return;
if (container != null)
OnReleaseRequestState (o, args);
HttpApplication application = o as HttpApplication;
if (application == null)
return;
if (handler != null)
handler.EndRequest (application.Context);
}
SessionStateStoreData GetStoreData (HttpContext context, string sessionId, bool isReadOnly) {
SessionStateStoreData item;
item = (isReadOnly) ?
handler.GetItem (context,
sessionId,
out storeLocked,
out storeLockAge,
out storeLockId,
out storeSessionAction)
:
handler.GetItemExclusive (context,
sessionId,
out storeLocked,
out storeLockAge,
out storeLockId,
out storeSessionAction);
if (storeLockId == null)
storeLockId = 0;
return item;
}
void WaitForStoreUnlock (HttpContext context, string sessionId, bool isReadonly) {
AutoResetEvent are = new AutoResetEvent (false);
TimerCallback tc = new TimerCallback (StoreUnlockWaitCallback);
CallbackState cs = new CallbackState (context, are, sessionId, isReadonly);
using (Timer timer = new Timer (tc, cs, 500, 500)) {
try {
are.WaitOne (executionTimeout, false);
}
catch {
storeData = null;
}
}
}
void StoreUnlockWaitCallback (object s) {
CallbackState state = (CallbackState) s;
SessionStateStoreData item = GetStoreData (state.Context, state.SessionId, state.IsReadOnly);
if (item == null && storeLocked && (storeLockAge > executionTimeout)) {
handler.ReleaseItemExclusive (state.Context, state.SessionId, storeLockId);
storeData = null; // Create new state
state.AutoEvent.Set ();
}
else if (item != null && !storeLocked) {
storeData = item;
state.AutoEvent.Set ();
}
}
HttpSessionStateContainer CreateContainer (string sessionId, SessionStateStoreData data, bool isNew, bool isReadOnly) {
if (data == null)
return new HttpSessionStateContainer (
sessionId, null, null, 0, isNew,
config.Cookieless, config.Mode, isReadOnly);
return new HttpSessionStateContainer (
sessionId,
data.Items,
data.StaticObjects,
data.Timeout,
isNew,
config.Cookieless,
config.Mode,
isReadOnly);
}
void OnSessionExpired (string id, SessionStateStoreData item) {
SessionStateUtility.RaiseSessionEnd (
CreateContainer (id, item, false, true),
this, EventArgs.Empty);
}
void OnSessionStart () {
EventHandler eh = events [startEvent] as EventHandler;
if (eh != null)
eh (this, EventArgs.Empty);
}
}
}
#endif

Some files were not shown because too many files have changed in this diff Show More