Esempio n. 1
0
        public async Task CanGetSessionFromCookie()
        {
            var store = new InMemorySessionStore();
            var session = await store.GetSession(null);

            var cookie = new Cookie(Constants.SessionKey, session.ID);

            var headers = new RequestHeaders(new Dictionary<string, string[]>());
            headers["Cookie"] = new string[] { cookie.ToHeaderString() };

            var mockRequest = new Mock<IRequest>();
            mockRequest.SetupGet(x => x.Path).Returns(new VirtualPath("~/"));
            mockRequest.SetupGet(x => x.Headers).Returns(headers);
            var mockResponse = new Mock<IResponse>();
            var processor = new RequestProcessor
                (null, store, null, new FeatureSet(null, new IFeature[0]), null, null, null);

            var ctx = processor.CreateContext(mockRequest.Object, mockResponse.Object, null);
            Assert.IsNotNull(ctx.Session);

            Assert.AreSame(session, ctx.Session);
            Console.WriteLine(ctx.Session.ID);
        }
Esempio n. 2
0
 private async Task PersistSession()
 {
     if (_session != null) {
         if (_session.ID != null) {
             var cookie = new Cookie(Constants.SessionKey, _session.ID) {
                 Expires = _session.Expires,
                 HttpOnly = true,
                 Secure = Request.IsSecure
             };
             Response.Headers.AddCookie(cookie);
         }
         await _session.Persist();
     }
 }
 public void AddCookie(Cookie cookie)
 {
     this.AddHeader("Set-Cookie", cookie.ToHeaderString());
 }
Esempio n. 4
0
 public void AddCookie(Cookie cookie)
 {
     this.AddHeader("Set-Cookie", cookie.ToHeaderString());
 }