本文整理汇总了C#中System.Web.SessionState.SessionStateItemCollection类的典型用法代码示例。如果您正苦于以下问题:C# SessionStateItemCollection类的具体用法?C# SessionStateItemCollection怎么用?C# SessionStateItemCollection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SessionStateItemCollection类属于System.Web.SessionState命名空间,在下文中一共展示了SessionStateItemCollection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FakeControllerContext
public FakeControllerContext(
IController controller,
string userName = null,
string[] roles = null,
NameValueCollection formParams = null,
NameValueCollection queryStringParams = null,
HttpCookieCollection cookies = null,
SessionStateItemCollection sessionItems = null,
NameValueCollection headers = null,
Uri uri = null
)
: base(new FakeHttpContext(
new FakePrincipal(
new FakeIdentity(userName),
roles),
formParams,
queryStringParams,
cookies,
sessionItems,
headers,
uri),
new RouteData(),
controller as ControllerBase)
{
}
示例2: TestUpdates
public void TestUpdates()
{
SessionStateItemCollection items = new SessionStateItemCollection();
items["Val1"] = "value";
byte[] serializedItems = Serialize(items);
Binary b = new Binary(serializedItems);
List<string> ids = new List<string>();
ICursor allSessions;
using (var mongo = new Mongo(config))
{
mongo.Connect();
allSessions = mongo["session_store"]["sessions"].FindAll();
foreach (Document session in allSessions.Documents)
{
string id = (string)session["SessionId"];
ids.Add(id);
}
}
foreach (string s in ids)
{
var sessionStore = new SessionStore("test");
sessionStore.UpdateSession(s, 2, b, "AppName", items.Count, 0);
}
}
示例3: MongoSessionDocument
public MongoSessionDocument()
{
ApplicationName = "WinDemo.Mongodb";
LockId = 0;
Locked = false;
Flags = 0;
User = "ZYTestUser";
Timeout = 50;
Created = DateTime.UtcNow;
LockDate = DateTime.UtcNow;
Expires = Created.AddMinutes(Timeout);
SessionStateItemCollection col = new SessionStateItemCollection();
col["key1"] = new
{
ID = new Random().Next(100, 100000),
Name = "ZY",
Age = 11
};
col["key2"] = new
{
ID = new Random().Next(100, 100000),
Name = "ZY",
Age = 11
};
SessionItems = col;
}
示例4: FakeHttpContext
public FakeHttpContext(string relativeUrl,
IPrincipal principal, NameValueCollection formParams,
NameValueCollection queryStringParams, HttpCookieCollection cookies,
SessionStateItemCollection sessionItems, NameValueCollection serverVariables)
: this(relativeUrl, null, principal, formParams, queryStringParams, cookies, sessionItems, serverVariables)
{
}
示例5: GetItem
public override SessionStateStoreData GetItem(HttpContext context,
string id,
out bool locked,
out TimeSpan lockAge,
out object lockId,
out SessionStateActions actions)
{
var redis = GetRedisConnection();
var getSessionData = redis.Hashes.GetAll(0, GetKeyForSessionId(id));
locked = false;
lockAge = new TimeSpan(0);
lockId = null;
actions = SessionStateActions.None;
if (getSessionData.Result == null) {
return null;
}
else {
var sessionItems = new SessionStateItemCollection();
var sessionDataHash = getSessionData.Result;
if (sessionDataHash.Count == 3) {
sessionItems = Deserialize(sessionDataHash["data"]);
var timeoutMinutes = BitConverter.ToInt32(sessionDataHash["timeoutMinutes"], 0);
redis.Keys.Expire(0, GetKeyForSessionId(id), timeoutMinutes * 60);
}
return new SessionStateStoreData(sessionItems,
SessionStateUtility.GetSessionStaticObjects(context),
redisConfig.SessionTimeout);
}
}
示例6: FakeHttpContext
public FakeHttpContext(
IPrincipal principal,
IFormParamsProvider formParams,
IQueryStringParamsProvider queryStringParams,
ICookieProvider cookies,
IServerVariablesParamsProvider serverVariablesParams,
IHeadersParamsProvider headersParams,
SessionStateItemCollection sessionItems,
HttpServerUtilityBase server,
FakeHttpRequest request,
IHttpContextBehavior contextBehavior)
{
User = principal;
_sessionItems = sessionItems ?? new SessionStateItemCollection();
_request = request ?? new FakeHttpRequest(formParams, queryStringParams, cookies, serverVariablesParams, headersParams);
_request.SetIsAuthenticated(User.Identity != null ? User.Identity.IsAuthenticated : false);
_server = server ?? new Mock<HttpServerUtilityBase>().Object;
var httpResponse = new Mock<HttpResponseBase>();
httpResponse.Setup(x => x.ApplyAppPathModifier(It.IsAny<string>())).Returns<string>(s => s);
_response = httpResponse.Object;
_behavior = contextBehavior;
_items = new Hashtable();
}
示例7: 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;
}
}
示例8: ExpectedRavenDbCallsAreMade
public void ExpectedRavenDbCallsAreMade()
{
// Arrange
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);
object lockId = 0;
string providedSessionId = "A sessionId";
SessionStateDocument sessionObject = TestSessionDocumentFactory.CreateSessionStateDocument(providedSessionId, expectedAppName);
sessionObject.Expiry = DateTime.UtcNow.AddDays(1);
var sessionItems = new SessionStateItemCollection();
sessionItems["ACar"] = new Car("A6", "Audi");
sessionObject.SessionItems = subject.Serialize(sessionItems);
SessionStateStoreData item = RavenSessionStateStoreProvider.Deserialize(null, sessionObject.SessionItems, 10);
MockDocumentSession.Setup(cmd => cmd.Store(It.IsAny<SessionStateDocument>())).Verifiable();
MockDocumentSession.Setup(cmd => cmd.SaveChanges()).Verifiable();
subject.Initialize("A name", keyPairs, MockDocumentStore.Object);
// Act
subject.CreateUninitializedItem(new HttpContext(new SimpleWorkerRequest("", "", "", "", new StringWriter())), providedSessionId, 10);
// Assert
MockDocumentSession.Verify(cmd => cmd.Store(It.IsAny<SessionStateDocument>()), Times.Once());
MockDocumentSession.Verify(cmd => cmd.SaveChanges(), Times.Once());
}
开发者ID:CorporateActionMan,项目名称:RavenDbSessionStateStoreProvider,代码行数:35,代码来源:CreateUninitializedItemTests.cs
示例9: SessionLifetimeReturnsSameInstanceForSameSessionAndDifferentInstanceForDifferentSession
public void SessionLifetimeReturnsSameInstanceForSameSessionAndDifferentInstanceForDifferentSession()
{
// Arrange
using (var container = new IocContainer())
{
var sessionItems1 = new SessionStateItemCollection();
var sessionItems2 = new SessionStateItemCollection();
var context1 = new FakeHttpContext("Http://fakeUrl1.com", null, null, null, null, sessionItems1);
var context2 = new FakeHttpContext("Http://fakeUrl2.com", null, null, null, null, sessionItems2);
HttpContextBase currentContext = null;
var lifetime = new SessionLifetime(() => currentContext); // better solution for injecting HttpContext ?
container.Register<IFoo>(c => new Foo1()).SetLifetime(lifetime);
// Act
currentContext = context1;
var result1 = container.Resolve<IFoo>();
var result2 = container.Resolve<IFoo>();
currentContext = context2;
var result3 = container.Resolve<IFoo>();
// Assert
Assert.IsNotNull(result1);
Assert.IsNotNull(result2);
Assert.IsNotNull(result3);
Assert.AreSame(result1, result2);
Assert.AreNotSame(result1, result3);
}
}
示例10: FakeHttpContext
public FakeHttpContext(FakePrincipal principal, NameValueCollection formParams, NameValueCollection queryStringParams, HttpCookieCollection cookies, SessionStateItemCollection sessionItems )
{
_principal = principal;
_formParams = formParams;
_queryStringParams = queryStringParams;
_cookies = cookies;
_sessionItems = sessionItems;
}
示例11: 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;
}
示例12: 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);
}
示例13: FakeHttpContext
public FakeHttpContext(string relativeUrl, FakePrincipal principal, NameValueCollection formParams, NameValueCollection queryStringParams, HttpCookieCollection cookies, SessionStateItemCollection sessionItems)
{
this.relativeUrl = relativeUrl;
this.principal = principal;
this.formParams = formParams;
this.queryStringParams = queryStringParams;
this.cookies = cookies;
this.sessionItems = sessionItems;
}
示例14: MockHttpContext
public MockHttpContext(string relativeUrl, Models.UserPrincipal principal, NameValueCollection formParams, NameValueCollection queryStringParams, HttpCookieCollection cookies, SessionStateItemCollection sessionItems)
{
_relativeUrl = relativeUrl;
_principal = principal;
_formParams = formParams;
_queryStringParams = queryStringParams;
_cookies = cookies;
_sessionItems = sessionItems;
}
示例15: 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();
}