Beispiel #1
0
        /// <summary>
        /// Stores session variables to ASP.NET session.
        /// </summary>
        internal protected override void Persist(PhpArray variables, ScriptContext context, HttpContext httpContext)
        {
            HttpSessionState state = httpContext.Session;

            if (state.Mode == SessionStateMode.InProc)
            {
                context.ReleaseArray(variables);

                // removes all items (some could be changed or removed in PHP):
                // TODO: some session variables could be added in ASP.NET application
                state.Clear();

                // populates session collection from variables:
                foreach (KeyValuePair <IntStringKey, object> entry in variables)
                {
                    // skips resources:
                    if (!(entry.Value is PhpResource))
                    {
                        state.Add(entry.Key.ToString(), entry.Value);
                    }
                }
            }
            else
            {
                // if the session is maintained out-of-process, serialize the entire $_SESSION autoglobal
                MemoryStream    stream    = new MemoryStream();
                BinaryFormatter formatter = new BinaryFormatter(null,
                                                                new StreamingContext(StreamingContextStates.Persistence));

                formatter.Serialize(stream, variables);

                // add the serialized $_SESSION to ASP.NET session:
                state[PhpNetSessionVars] = stream.ToArray();
            }
        }
Beispiel #2
0
		/// <summary>
		/// Stores session variables to ASP.NET session.
		/// </summary>
		internal protected override void Persist(PhpArray variables, ScriptContext context, HttpContext httpContext)
		{
			HttpSessionState state = httpContext.Session;

            if (state.Mode == SessionStateMode.InProc)
			{
                context.ReleaseArray(variables);

                // removes all items (some could be changed or removed in PHP):
                // TODO: some session variables could be added in ASP.NET application
                state.Clear();
                
                // populates session collection from variables:
				foreach (KeyValuePair<IntStringKey, object> entry in variables)
				{
					// skips resources:
					if (!(entry.Value is PhpResource))
						state.Add(entry.Key.ToString(), entry.Value);
				}
			}
			else
			{
				// if the session is maintained out-of-process, serialize the entire $_SESSION autoglobal
				MemoryStream stream = new MemoryStream();
				BinaryFormatter formatter = new BinaryFormatter(null,
					new StreamingContext(StreamingContextStates.Persistence));

				formatter.Serialize(stream, variables);

				// add the serialized $_SESSION to ASP.NET session:
                state[PhpNetSessionVars] = stream.ToArray();
			}
		}