Exemplo 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);
        }
Exemplo 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();
     }
 }
Exemplo n.º 3
0
 public void AddCookie(Cookie cookie)
 {
     this.AddHeader("Set-Cookie", cookie.ToHeaderString());
 }
Exemplo n.º 4
0
 public void AddCookie(Cookie cookie)
 {
     this.AddHeader("Set-Cookie", cookie.ToHeaderString());
 }