/// <summary>
        /// Decrypts the cookie information and returns it's value.
        /// </summary>
        public static string Decrypt(Cookie cookie)
        {
            //https://github.com/SignalR/SignalR/issues/2163, http://stackoverflow.com/questions/26336989/cookie-encoding-in-base64-cannot-be-sent-correctly-to-server
            //var urlEncoded = HttpUtility.UrlEncode(cookie.Value);
            //var bytes = Convert.FromBase64String(urlEncoded);
            var bytes = HttpServerUtility.UrlTokenDecode(cookie.Value);
            var unprotected = MachineKey.Unprotect(bytes, EncryptionSalt);
            string cookieValue = UTF8Encoding.UTF8.GetString(unprotected);

            return cookieValue;
        }
 public bool AuthorizeHubMethodInvocation(Microsoft.AspNet.SignalR.Hubs.IHubIncomingInvokerContext hubIncomingInvokerContext, bool appliesToMethod)
 {
     if (hubIncomingInvokerContext.Hub.Context.RequestCookies.ContainsKey("ASP.NET_SignalRExtendLib_SessionKey"))
     {
         ServerContext.Session(hubIncomingInvokerContext.Hub.Context).OnInvocal();
     }
     else
     {
         string sessionId = ServerContext.SessionPool.Create();
         Cookie ck = new Cookie("ASP.NET_SignalRExtendLib_SessionKey", sessionId);
         hubIncomingInvokerContext.Hub.Context.RequestCookies.Add("ASP.NET_SignalRExtendLib_SessionKey", ck);
         if (hubIncomingInvokerContext.Hub is ICookieDistrinctRequest)
         {
             (hubIncomingInvokerContext.Hub as ICookieDistrinctRequest).AppendCookie("ASP.NET_SignalRExtendLib_SessionKey", sessionId);
         }
     }
     return true;
 }