当前位置: 首页>>代码示例>>C#>>正文


C# SessionStateItemCollection.Serialize方法代码示例

本文整理汇总了C#中System.Web.SessionState.SessionStateItemCollection.Serialize方法的典型用法代码示例。如果您正苦于以下问题:C# SessionStateItemCollection.Serialize方法的具体用法?C# SessionStateItemCollection.Serialize怎么用?C# SessionStateItemCollection.Serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.SessionState.SessionStateItemCollection的用法示例。


在下文中一共展示了SessionStateItemCollection.Serialize方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Serialize

 private byte[] Serialize(SessionStateItemCollection items)
 {
   MemoryStream ms = new MemoryStream();
   BinaryWriter writer = new BinaryWriter(ms);
   if (items != null)
   {
     items.Serialize(writer);
   }
   writer.Close();
   return ms.ToArray();
 }
开发者ID:jimmy00784,项目名称:mysql-connector-net,代码行数:11,代码来源:SessionTests.cs

示例2: SerializeSessionState

        /// <summary>
        /// Session 정보를 직렬화합니다. (일반적인 직렬화 방식은 안되고, SessionStateItemCollection 자체의 Serialize를 사용해서 직렬화합니다.)
        /// </summary>
        /// <param name="items"></param>
        /// <returns></returns>
        public static byte[] SerializeSessionState(SessionStateItemCollection items) {
            if(IsDebugEnabled)
                log.Debug("세션 정보를 직렬화를 수행합니다...");

            if(items == null)
                return new byte[0];

            using(var ms = new MemoryStream())
            using(var writer = new BinaryWriter(ms)) {
                items.Serialize(writer);
                writer.Close();

                return ms.ToArray();
            }
        }
开发者ID:debop,项目名称:NFramework,代码行数:20,代码来源:WebTool.Session.cs

示例3: save

        public void save()
        {
            Data.sName = "aa";
            Data.dBaseRadius = 2;
            Data.dNoseRadius = .5;

            String x = "";

            foreach (string key in HttpContext.Current.Session.Keys)
            {
                x += key + " - " + HttpContext.Current.Session[key] + ";";
            }

            //SessionStateItemCollection items = HttpContext.Current.Session.

            SessionStateItemCollection items = new SessionStateItemCollection();

            items["Name"] = "NN";
            items["Desc"] = "DD";

            try
            {
                System.IO.BinaryWriter writer = new System.IO.BinaryWriter(
                  System.IO.File.Open(HttpContext.Current.Server.MapPath("./session_collection.bin"), System.IO.FileMode.Create));

                items.Serialize(writer);
                writer.Close();

                items["Name"] = "";
                items["Desc"] = "";

                System.IO.BinaryReader reader = new System.IO.BinaryReader(
                    System.IO.File.Open(HttpContext.Current.Server.MapPath("./session_collection.bin"), System.IO.FileMode.Open));

                items = SessionStateItemCollection.Deserialize(reader);

                String x2 = items["Name"].ToString();
                String y2 = items["Desc"].ToString();
            }
            catch (Exception e)
            {
                String err = e.StackTrace;
            }
        }
开发者ID:John1900,项目名称:G-Cam,代码行数:44,代码来源:PersistData.cs

示例4: serialize

        private string serialize(SessionStateItemCollection items)
        {
            MemoryStream ms = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(ms);

            if (items != null)
                items.Serialize(writer);

            writer.Close();

            return Convert.ToBase64String(ms.ToArray());
        }
开发者ID:JaredHatfield,项目名称:aws-dotnet-session-provider,代码行数:12,代码来源:DynamoDBSessionStateStore.cs

示例5: serialize

        private string[] serialize(SessionStateItemCollection items)
        {
            MemoryStream ms = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(ms);

            if (items != null)
                items.Serialize(writer);

            writer.Close();

            byte[] raw = ms.ToArray();

            ms.Close();

            List<string> parts = new List<string>();
            byte[] segment;

            int scount = (raw.Length / SHARD_SIZE);
            int tcount = raw.Length - (scount * SHARD_SIZE);

            for (int pos = 0; pos < scount; pos++)
            {
                segment = new byte[SHARD_SIZE];
                int startIndex = pos * SHARD_SIZE;
                Buffer.BlockCopy(raw, pos * SHARD_SIZE, segment, 0, SHARD_SIZE);
                parts.Add(Convert.ToBase64String(segment));
            }
            segment = new byte[tcount];
            Buffer.BlockCopy(raw, scount * SHARD_SIZE, segment, 0, tcount);
            parts.Add(Convert.ToBase64String(segment));

            return parts.ToArray();
        }
开发者ID:jeffersonjhunt,项目名称:aws-sdk-net,代码行数:33,代码来源:DynamoDBSessionStateStore.cs

示例6: Serialize

        private string Serialize(SessionStateItemCollection items)
        {
            using (var stream = new MemoryStream())
            {
                using (var writer = new BinaryWriter(stream))
                {
                    if (items != null)
                        items.Serialize(writer);

                    writer.Flush();
                    writer.Close();

                    return Convert.ToBase64String(stream.ToArray());
                }
            }
        }
开发者ID:sumothecat,项目名称:RavenDbSessionStateStoreProvider,代码行数:16,代码来源:RavenSessionStateStoreProvider.cs

示例7: Serialize

        /// <summary>
        /// Serialize
        /// (SessionStateItemCollection → Base64)
        /// </summary>
        /// <param name="items">アイテム</param>
        /// <returns>Base64</returns>
        private string Serialize(SessionStateItemCollection items)
        {
            using (MemoryStream ms = new MemoryStream())
            {
                using (BinaryWriter writer = new BinaryWriter(ms))
                {
                    if (items != null)
                        items.Serialize(writer);
                }

                return Convert.ToBase64String(ms.ToArray());
            }
        }
开发者ID:takeman,项目名称:OpenTouryo,代码行数:19,代码来源:CstSqlSessionStateProvider.cs

示例8: Serialize

        /// <summary>
        /// Convert a SessionStateItemCollection into a Base64 string
        /// </summary>
        private static string Serialize(SessionStateItemCollection items)
        {
            if (items == null || items.Count < 1)
                return string.Empty;

            using (MemoryStream mStream = new MemoryStream())
            {
                using (BinaryWriter bWriter = new BinaryWriter(mStream))
                {
                    items.Serialize(bWriter);
                    bWriter.Close();
                }

                return Convert.ToBase64String(mStream.ToArray());
            }
        }
开发者ID:sztupy,项目名称:shaml,代码行数:19,代码来源:NHSessionStateStoreProvider.cs

示例9: Serialize

        //
        // Serialize is called by the SetAndReleaseItemExclusive method to
        // convert the SessionStateItemCollection into a Binary.
        //
        private byte[] Serialize(SessionStateItemCollection items)
        {
            MemoryStream ms = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(ms);
            try
            {
                if (items != null)
                    items.Serialize(writer);
            }
            catch (Exception e)
            {
                if (WriteExceptionsToEventLog)
                {
                    WriteToEventLog(e, "GetSessionStoreItem");
                    throw new ProviderException(e.Message, e.InnerException);
                }
                else
                    throw e;

            }
            finally
            {
                writer.Close();
            }
            return ms.ToArray();
        }
开发者ID:GunioRobot,项目名称:MongoSessionStore,代码行数:30,代码来源:MongoSessionStoreProvider.cs

示例10: Serialize

 private byte[] Serialize(SessionStateItemCollection items)
 {
     MemoryStream ms = new MemoryStream();
     BinaryWriter writer = new BinaryWriter(ms);
     try
     {
         if (items != null)
             items.Serialize(writer);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
     finally
     {
         writer.Close();
     }
     return ms.ToArray();
 }
开发者ID:GunioRobot,项目名称:MongoSessionStore,代码行数:19,代码来源:ConnectionTest.cs

示例11: Serialize

        private static byte[] Serialize(SessionStateItemCollection items)
        {
            using (var ms = new MemoryStream())
            {
                using (var writer = new BinaryWriter(ms))
                {
                    if (items != null)
                        items.Serialize(writer);

                    writer.Close();

                    return ms.ToArray();
                }
            }
        }
开发者ID:kumaie,项目名称:AspNetRedisProviders,代码行数:15,代码来源:RedisSessionStateStoreProvider.cs

示例12: Serialize

        private string Serialize(SessionStateItemCollection items)
        {
            using (MemoryStream ms = new MemoryStream()) {
            using (BinaryWriter writer = new BinaryWriter(ms)) {
               if (items != null) {
                  items.Serialize(writer);
               }
            }

            var encryptedData = MachineKey.Protect(ms.ToArray(), "Session Data");
            return Convert.ToBase64String(encryptedData);
             }
        }
开发者ID:bgrebil,项目名称:CookieJar,代码行数:13,代码来源:CookieSessionStateStore.cs

示例13: Serialize

        public void Serialize(SessionStateItemCollection items)
        {
            var ms = new MemoryStream();
            var writer = new BinaryWriter(ms);

            if (items != null)
                items.Serialize(writer);

            writer.Close();

            _serializedSessionData = ms.ToArray();
        }
开发者ID:Ben5000,项目名称:MemcachedSessionProvider,代码行数:12,代码来源:SessionData.cs

示例14: Serialize

        private string Serialize(SessionStateItemCollection items)
        {
            MemoryStream ms = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(ms);

            List<string> itemsABorrar = new List<string>();
            foreach (string item in items.Keys)
            {
                if (!(items[item].GetType().IsSerializable))
                    itemsABorrar.Add(item);
            }

            foreach(string item in itemsABorrar)
                items.Remove(item);

            if (items != null)
            {
                items.Serialize(writer);
            }

            writer.Close();

            return Convert.ToBase64String(ms.ToArray());
        }
开发者ID:rrdiaz,项目名称:MongoDBSharedSession,代码行数:24,代码来源:SharedSessionStoreProvider.cs


注:本文中的System.Web.SessionState.SessionStateItemCollection.Serialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。