• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# SessionState.SessionStateStoreData类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



SessionStateStoreData类属于System.Web.SessionState命名空间,在下文中一共展示了SessionStateStoreData类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: GetItemExclusive_RecordFound

        public void GetItemExclusive_RecordFound()
        {
            Utility.SetConfigUtilityToDefault();
            string id = "session-id";
            bool locked;
            TimeSpan lockAge;
            object lockId = null;
            SessionStateActions actions;

            ISessionStateItemCollection sessionStateItemCollection = new ChangeTrackingSessionStateItemCollection();
            sessionStateItemCollection["session-key"] = "session-value";
            SessionStateStoreData sssd = new SessionStateStoreData(sessionStateItemCollection, null, 15);

            ISessionStateItemCollection sessionData = new ChangeTrackingSessionStateItemCollection();
            sessionData["session-key"] = "session-value";

            ISessionStateItemCollection mockSessionData = null;
            object mockLockId = 0;
            int mockSessionTimeout;
            int sessionTimeout = (int)RedisSessionStateProvider.configuration.SessionTimeout.TotalMinutes;
            var mockCache = A.Fake<ICacheConnection>();
            A.CallTo(() => mockCache.TryTakeWriteLockAndGetData(A<DateTime>.Ignored, 90, out mockLockId, out mockSessionData, out mockSessionTimeout)).Returns(true).AssignsOutAndRefParameters(0, sessionData, (int)RedisSessionStateProvider.configuration.SessionTimeout.TotalMinutes);

            RedisSessionStateProvider sessionStateStore = new RedisSessionStateProvider();
            sessionStateStore.cache = mockCache;
            SessionStateStoreData sessionStateStoreData = sessionStateStore.GetItemExclusive(null, id, out locked, out lockAge, out lockId, out actions);
            A.CallTo(() => mockCache.TryTakeWriteLockAndGetData(A<DateTime>.Ignored, 90, out mockLockId, out sessionData, out sessionTimeout)).MustHaveHappened();

            Assert.Equal(true, Utility.CompareSessionStateStoreData(sessionStateStoreData, sssd));
            Assert.Equal(false, locked);
            Assert.Equal(TimeSpan.Zero, lockAge);
            Assert.Equal(actions, SessionStateActions.None);
        }
开发者ID:ynoami,项目名称:aspnet-redis-providers,代码行数:33,代码来源:RedisSessionStateProviderTests.cs


示例2: CreateNewStoreData_WithEmptyStore

 public void CreateNewStoreData_WithEmptyStore()
 {
     Utility.SetConfigUtilityToDefault();
     SessionStateStoreData sssd = new SessionStateStoreData(new ChangeTrackingSessionStateItemCollection(), null, 900);
     RedisSessionStateProvider sessionStateStore = new RedisSessionStateProvider();
     Assert.Equal(true, Utility.CompareSessionStateStoreData(sessionStateStore.CreateNewStoreData(null, 900),sssd));
 }
开发者ID:Remy-Burney-Powerfront,项目名称:aspnet-redis-providers,代码行数:7,代码来源:RedisSessionStateProviderTests.cs


示例3: Save

 public void Save(ISessionStateContext context, IDictionary<string, object> values)
 {
     EnsureInitialized(context);
     var sessionState = new SessionStateStoreData(new SessionStateItemCollection().AddItems(values), new HttpStaticObjectsCollection(), _timeout);
     var data = new SessionStateEncoding().Serialize(sessionState);
     _sessionStore.Save(SqlSessionId.Create(context.MetabasePath, context.SessionId), data);
 }
开发者ID:mikeobrien,项目名称:ClassicAspRemoteSession,代码行数:7,代码来源:SqlSessionStateProvider.cs


示例4: CompareSessionStateStoreData

        internal static bool CompareSessionStateStoreData(SessionStateStoreData obj1, SessionStateStoreData obj2)
        {
            if ((obj1 == null && obj2 != null) || (obj1 != null && obj2 == null))
            {
                return false;
            }
            else if (obj1 != null && obj2 != null)
            {
                if (obj1.Timeout != obj2.Timeout)
                {
                    return false;
                }

                System.Collections.Specialized.NameObjectCollectionBase.KeysCollection keys1 = obj1.Items.Keys;
                System.Collections.Specialized.NameObjectCollectionBase.KeysCollection keys2 = obj2.Items.Keys;

                if ((keys1 != null && keys2 == null) || (keys1 == null && keys2 != null))
                {
                    return false;
                }
                else if (keys1 != null && keys2 != null)
                {
                    foreach (string key in keys1)
                    {
                        if (obj2.Items[key] == null)
                        {
                            return false;
                        }
                    }
                }

            }
            return true;
        }
开发者ID:Remy-Burney-Powerfront,项目名称:aspnet-redis-providers,代码行数:34,代码来源:Utility.cs


示例5: GetItem

        /// <summary>
        /// Called when SessionState = ReadOnly
        /// </summary>
        public override SessionStateStoreData GetItem(HttpContext context, string id, out bool locked, out TimeSpan lockAge, out object lockId, out SessionStateActions actions)
        {
            RedisConnection redisConnection = ConnectionUtils.Connect("10.0.0.3:6379");
            {
                redisConnection.Open();

                var result = redisConnection.Strings.Get(0, id);
                byte[] raw = redisConnection.Wait(result);

                actions = SessionStateActions.None;

                SessionEntity sessionEntity = GetFromBytes(raw);
                if (sessionEntity == null || sessionEntity.SessionItems == null )
                {
                    locked = false;
                    lockId = _lock;
                    lockAge = TimeSpan.MinValue;
                    return null;
                }

                ISessionStateItemCollection sessionItems = new SessionStateItemCollection();
                foreach (string key in sessionEntity.SessionItems.Keys)
                {
                    sessionItems[key] = sessionEntity.SessionItems[key];
                }

                SessionStateStoreData data = new SessionStateStoreData(sessionItems, _staticObjects, context.Session.Timeout);

                locked = false;
                lockId = _lock;
                lockAge = TimeSpan.MinValue;
                return data;
            }
        }
开发者ID:ThomasSchmidt,项目名称:MixedStuff,代码行数:37,代码来源:RedisSessionStateStoreProvider.cs


示例6: SetAndReleaseItemExclusive

        public override void SetAndReleaseItemExclusive(HttpContext context, string id, SessionStateStoreData item, object lockId, bool newItem)
        {
            var sessionStore = SessionStore.Instance;
            try
            {

                byte[] serializedItems = Serialize((SessionStateItemCollection)item.Items);
                Binary sessionItems = new Binary(serializedItems);

                if (newItem)
                {
                    // Delete an existing expired session if it exists.
                    sessionStore.EvictExpiredSession(id, _applicationName);

                    // insert new session item.
                    Session session = new Session(id, this._applicationName, item.Timeout, sessionItems, item.Items.Count, 0);
                    sessionStore.Insert(session);
                }
                else
                {
                    sessionStore.UpdateSession(id, item.Timeout, sessionItems, this._applicationName, item.Items.Count, lockId);
                }
            }
            catch (Exception e)
            {
                if (WriteExceptionsToEventLog)
                {
                    WriteToEventLog(e, "SetAndReleaseItemExclusive");
                    throw new ProviderException(e.Message, e.InnerException);
                }
                else
                    throw e;
            }
        }
开发者ID:jango2015,项目名称:MongoSessionStore,代码行数:34,代码来源:MongoSessionStoreProvider.cs


示例7: CreateNewStoreData

 public override SessionStateStoreData CreateNewStoreData(HttpContext context, int timeout)
 {
     var sessionItems = new SessionStateItemCollection();
     string sessionString = JsonConvert.SerializeObject(sessionItems);
     cache.PutAsync(context.Session.SessionID, sessionString, TimeSpan.FromMinutes(timeout));
     var data = new SessionStateStoreData(sessionItems, null, timeout);
     return data;
 }
开发者ID:jahmad-fareportal,项目名称:CacheSharp,代码行数:8,代码来源:CacheSharpSessionProvider.cs


示例8: SetUp

 public void SetUp()
 {
     var configure = new MongoConfigurationBuilder();
     configure.ConnectionStringAppSettingKey("mongoserver");
     config = configure.BuildConfiguration();
     SessionStateItemCollection sessionItemsCollection = new SessionStateItemCollection();
     HttpStaticObjectsCollection staticObjectsCollection = new HttpStaticObjectsCollection();
     item = new SessionStateStoreData(sessionItemsCollection, staticObjectsCollection, 1);
 }
开发者ID:jango2015,项目名称:MongoSessionStore,代码行数:9,代码来源:SessionStoreTest.cs


示例9: CreateNewStoreData

        /// <summary>
        /// Creates a new System.Web.SessionState.SessionStateStoreData object to be
        /// used for the current request.
        /// </summary>
        /// <param name="context">The current request context</param>
        /// <param name="timeout">The session-state System.Web.SessionState.HttpSessionState.Timeout value
        /// for the new System.Web.SessionState.SessionStateStoreData.</param>
        /// <returns>A new System.Web.SessionState.SessionStateStoreData for the current request.</returns>
        public override SessionStateStoreData CreateNewStoreData(HttpContext context, int timeout)
        {
            SessionStateStoreData data = new SessionStateStoreData(
                new SessionStateItemCollection(),
                SessionStateUtility.GetSessionStaticObjects(context),
                timeout);

            return data;
        }
开发者ID:rrdiaz,项目名称:MongoDBSharedSession,代码行数:17,代码来源:SharedSessionStoreProvider.cs


示例10: Should_Encode_Session_Data

 public void Should_Encode_Session_Data()
 {
     var encoding = new SessionStateEncoding();
     var sessionState = new SessionStateStoreData(new SessionStateItemCollection(), new HttpStaticObjectsCollection(), 20);
     sessionState.Items[Constants.SessionStateKey1] = Constants.SessionStateValue1;
     sessionState.Items[Constants.SessionStateKey2] = Constants.SessionStateValue2;
     sessionState.Items[Constants.SessionStateKey3] = Constants.SessionStateValue3;
     encoding.Serialize(sessionState).SequenceEqual(Constants.SessionStateSerializedBytes).ShouldBeTrue();
 }
开发者ID:mikeobrien,项目名称:ClassicAspRemoteSession,代码行数:9,代码来源:SessionStateEncodingTests.cs


示例11: Init

        public RedisASPSessionVariantDictionary Init(RedisASPSessionStateProvider sessionProvider, SessionStateStoreData storeData, string sessionId, int expiry)
        {
            //PFSession.Log.Debug($"PFRedisVariantDictionary:Init:{hashkey}");
            //System.IO.File.AppendAllText(@"C:\\log files\\pfsession.log", $"PFRedisVariantDictionary:Init:{hashkey}");
            this.sessionId = sessionId;
            this.sessionProvider = sessionProvider;
            this.storeData = storeData;

            return this;
        }
开发者ID:Remy-Burney-Powerfront,项目名称:aspnet-redis-providers,代码行数:10,代码来源:RedisASPSessionVariantDictionary.cs


示例12: SetAndReleaseItemExclusive

        public override void SetAndReleaseItemExclusive(HttpContext context, string id, SessionStateStoreData item, object lockId, bool newItem)
        {
            ISessionStateItemCollection sessionItems = null;
            HttpStaticObjectsCollection staticObjects = null;

            if (item.Items.Count > 0)
                sessionItems = item.Items;
            if (!item.StaticObjects.NeverAccessed)
                staticObjects = item.StaticObjects;

            RedisSessionState state2 = new RedisSessionState(sessionItems, staticObjects, item.Timeout);
            RedisHelper.Set<string>(id, state2.ToJson(), DateTime.Now.AddHours(1));
        }
开发者ID:JamesFoxChen,项目名称:AspNetSessionManage,代码行数:13,代码来源:RedisSessionStateStore.cs


示例13: RaiseSessionOnEnd

 internal void RaiseSessionOnEnd(string id, SessionStateStoreData item)
 {
     HttpSessionStateContainer container = new HttpSessionStateContainer(id, item.Items, item.StaticObjects, item.Timeout, false, SessionStateModule.s_configCookieless, SessionStateModule.s_configMode, true);
     HttpSessionState sessionState = new HttpSessionState(container);
     if (HttpRuntime.ShutdownInProgress)
     {
         this.RaiseOnEnd(sessionState);
     }
     else
     {
         SessionOnEndTargetWorkItem item2 = new SessionOnEndTargetWorkItem(this, sessionState);
         WorkItem.PostInternal(new WorkItemCallback(item2.RaiseOnEndCallback));
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:14,代码来源:SessionOnEndTarget.cs


示例14: Serialize

 public byte[] Serialize(SessionStateStoreData sessionState)
 {
     var hasItems = sessionState.Items != null && sessionState.Items.Count > 0;
     var hasStaticObjects = sessionState.StaticObjects != null && !sessionState.StaticObjects.NeverAccessed;
     var stream = new MemoryStream();
     var writer = new BinaryWriter(stream);
     writer.Write(sessionState.Timeout);
     writer.Write(hasItems);
     writer.Write(hasStaticObjects);
     if (hasItems) ((SessionStateItemCollection)sessionState.Items).Serialize(writer);
     if (hasStaticObjects) sessionState.StaticObjects.Serialize(writer);
     writer.Write(byte.MaxValue);
     return stream.ToArray();
 }
开发者ID:mikeobrien,项目名称:ClassicAspRemoteSession,代码行数:14,代码来源:SessionStateEncoding.cs


示例15: DeserializeToSessionStateStoreData

        /// <summary>
        /// Deserializes a base 64 string to a SessionStateStoreData object.
        /// </summary>
        /// <param name="base64String">The base64 string.</param>
        /// <param name="context">The context.</param>
        /// <param name="timeout">The timeout.</param>
        /// <returns></returns>
        public static SessionStateStoreData DeserializeToSessionStateStoreData(this string base64String, HttpContext context, int timeout)
        {
            using (var memoryStream = new MemoryStream(Convert.FromBase64String(base64String)))
            {
                var sessionItems = new SessionStateItemCollection();
                if (memoryStream.Length > 0)
                {
                    using (var reader = new BinaryReader(memoryStream))
                    {
                        sessionItems = SessionStateItemCollection.Deserialize(reader);
                    }
                }

                var sessionStateStoreData = new SessionStateStoreData(sessionItems, SessionStateUtility.GetSessionStaticObjects(context), timeout);
                return sessionStateStoreData;
            }
        }
开发者ID:QuintSys,项目名称:Web.Providers.MongoDBSessionStateStore,代码行数:24,代码来源:Base64StringExtensions.cs


示例16: GetItem

 public override SessionStateStoreData GetItem(HttpContext context, string id, out bool locked,
     out TimeSpan lockAge, out object lockId,
     out SessionStateActions actions)
 {
     // set default out parameters
     locked = false;
     lockAge = new TimeSpan();
     lockId = null;
     actions = SessionStateActions.None;
     // try to get the session from cache.
     string sessionString = cache.GetAsync<string>(id).Result;
     if (string.IsNullOrEmpty(sessionString))
         return null;
     var sessionItems = JsonConvert.DeserializeObject<SessionStateItemCollection>(sessionString);
     var data = new SessionStateStoreData(sessionItems, null, 60); // todo: set timeout.
     return data;
 }
开发者ID:jahmad-fareportal,项目名称:CacheSharp,代码行数:17,代码来源:CacheSharpSessionProvider.cs


示例17: Serialize

        public static byte[] Serialize(SessionStateStoreData sessionData)
        {
            byte sessionFlag = 0;
            MemoryStream stream = null;
            byte[] buffer = null;
            try
            {
                stream = new MemoryStream();
                BinaryWriter writer = new BinaryWriter(stream);

                if (sessionData.Items != null)
                {
                    sessionFlag = (byte)(sessionFlag | SESSION_ITEMS);
                }
                if (sessionData.StaticObjects != null && !sessionData.StaticObjects.NeverAccessed)
                {
                    sessionFlag = (byte)(sessionFlag | SESSION_STATIC_ITEMS);
                }
                writer.Write(sessionFlag);

                if ((byte)(sessionFlag & SESSION_ITEMS) == SESSION_ITEMS)
                {
                    ((SessionStateItemCollection)sessionData.Items).Serialize(writer);
                }
                if ((byte)(sessionFlag & SESSION_STATIC_ITEMS) == SESSION_STATIC_ITEMS)
                {
                    sessionData.StaticObjects.Serialize(writer);
                }
                writer.Write(sessionData.Timeout);
            }
            finally
            {
                if (stream != null)
                {
                    buffer = stream.ToArray();
                    stream.Close();
                }
            }
            return buffer;
        }
开发者ID:javithalion,项目名称:NCache,代码行数:40,代码来源:SessionSerializationUtil.cs


示例18: SetAndReleaseItemExclusive

        public override void SetAndReleaseItemExclusive(HttpContext context, string id, SessionStateStoreData item, object lockId, bool newItem)
        {
            using (var memoryStream = new MemoryStream())
            {
                using (var binaryWriter = new BinaryWriter(memoryStream))
                {
                    ((SessionStateItemCollection)item.Items).Serialize(binaryWriter);

                    if (newItem)
                    {
                        var query = Query.And(Query.EQ("applicationVirtualPath", HostingEnvironment.ApplicationVirtualPath), Query.EQ("id", id));
                        this.mongoCollection.Remove(query);

                        var bsonDocument = new BsonDocument
                        {
                            { "applicationVirtualPath", HostingEnvironment.ApplicationVirtualPath },
                            { "created", DateTime.Now },
                            { "expires", DateTime.Now.AddMinutes(item.Timeout) },
                            { "id", id },
                            { "lockDate", DateTime.Now },
                            { "locked", false },
                            { "lockId", 0 },
                            { "sessionStateActions", SessionStateActions.None },
                            { "sessionStateItems", memoryStream.ToArray() },
                            { "sessionStateItemsCount", item.Items.Count },
                            { "timeout", item.Timeout }
                        };

                        this.mongoCollection.Insert(bsonDocument);
                    }
                    else
                    {
                        var query = Query.And(Query.EQ("applicationVirtualPath", HostingEnvironment.ApplicationVirtualPath), Query.EQ("id", id), Query.EQ("lockId", lockId.ToString()));
                        var upate = Update.Set("expires", DateTime.Now.Add(this.sessionStateSection.Timeout)).Set("items", memoryStream.ToArray()).Set("locked", false).Set("sessionStateItemsCount", item.Items.Count);
                        this.mongoCollection.Update(query, upate);
                    }
                }
            }
        }
开发者ID:JasonSHD,项目名称:SaveASpot,代码行数:39,代码来源:MongoDBSessionStateProvider.cs


示例19: RaiseSessionOnEnd

        internal void RaiseSessionOnEnd(String id, SessionStateStoreData item) {
            HttpSessionStateContainer sessionStateContainer = new HttpSessionStateContainer(
                    id,
                    item.Items,
                    item.StaticObjects,
                    item.Timeout,
                    false,
                    SessionStateModule.s_configCookieless,
                    SessionStateModule.s_configMode,
                    true);

            HttpSessionState    sessionState = new HttpSessionState(sessionStateContainer);

            if (HttpRuntime.ShutdownInProgress) {
                // call directly when shutting down
                RaiseOnEnd(sessionState);
            }
            else {
                // post via thread pool
                SessionOnEndTargetWorkItem workItem = new SessionOnEndTargetWorkItem(this, sessionState);
                WorkItem.PostInternal(new WorkItemCallback(workItem.RaiseOnEndCallback));
            }
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:23,代码来源:SessionStateModule.cs


示例20: NewItemCallsSessionStore

        public void NewItemCallsSessionStore()
        {
            // Arrange & Act
            string expectedAppName = "You are everything ... to me";
            string appPath = "Application path";
            var subject = TestStoreProviderFactory.SetupStoreProvider(appPath, MockHostingProvider);
            NameValueCollection keyPairs = new NameValueCollection();
            keyPairs.Set("applicationName", expectedAppName);
            subject.Initialize("", keyPairs, MockDocumentStore.Object);

            SessionStateStoreData sessionData = new SessionStateStoreData(
                new SessionStateItemCollection(),
                new HttpStaticObjectsCollection(),
                20
                );

            subject.SetAndReleaseItemExclusive(new HttpContext(new SimpleWorkerRequest("", "", "", "", new StringWriter())), "A sessionId", sessionData, new object(), true);

            MockDocumentSession.Setup(cmd => cmd.Store(It.IsAny<SessionStateDocument>())).Verifiable();

            // Assert
            MockDocumentSession.Verify(cmd => cmd.Store(It.IsAny<SessionStateDocument>()), Times.Once());
        }
开发者ID:CorporateActionMan,项目名称:RavenDbSessionStateStoreProvider,代码行数:23,代码来源:SetAndReleaseItemExclusiveTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# UI.AsyncPostBackTrigger类代码示例发布时间:2022-05-26
下一篇:
C# SessionState.SessionStateItemCollection类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap