Ejemplo n.º 1
0
        void SendMessage(object command, string optionalId)
        {
            var auth = FormsAuth.GetSessionIdentityFromRequest();


            var envelopeId = optionalId ?? Guid.NewGuid().ToString().ToLowerInvariant();
            var eb         = new EnvelopeBuilder(envelopeId);

            if (auth.HasValue)
            {
                eb.AddString("web-user", auth.Value.User.Id.ToString(CultureInfo.InvariantCulture));
                eb.AddString("web-token", auth.Value.Token);
            }
            eb.AddItem(command);

            _writer.PutMessage(_streamer.SaveEnvelopeData(eb.Build()));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes the session, using the auth information
        /// associated with the current request
        /// </summary>
        public static void InitializeSessionFromRequest()
        {
            var context = HttpContext.Current;

            // we are fine
            if (context.Session[AccountSessionKey] != null)
            {
                return;
            }

            // unauthenticated session here
            if (!context.Request.IsAuthenticated)
            {
                return;
            }

            // authenticated session but without our data.
            // recover expired session (or use cookie)

            Debug.WriteLine("Session initialization attempt");
            FormsAuth
            .GetSessionIdentityFromRequest()
            .Apply(InitializeSession);
        }