コード例 #1
0
        /// <summary>
        /// Serializes session data into JSON.
        /// </summary>
        /// <param name="session">The Session data</param>
        /// <returns>A JSON representation</returns>
        internal static string Serialize(Session session)
        {
            var values = new SessionSerializer
            {
                CreatedAt = session.CreatedAt,
                Duration = session.Duration,
                Values = session.Values
            };

            using (var writer = new StringWriter())
            using (var jsonWriter = new JsonTextWriter(writer))
            {
                var serializer = new JsonSerializer();
                serializer.Serialize(jsonWriter, values);
                return writer.ToString();
            }
        }
コード例 #2
0
 /// <summary>
 /// Gets the session data from the current context.
 /// </summary>
 /// <param name="context"></param>
 /// <param name="create">If true, creates a new Session if it doesn't exist</param>
 /// <returns>The Session data</returns>
 private static Session GetSession(HttpContextBase context, bool create)
 {
     var session = context.Items[ItemKey] as Session;
     if (session == null && create)
     {
         session = new Session(Configuration.Duration);
         context.Items[ItemKey] = session;
     }
     return session;
 }