コード例 #1
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="isActive">Is the user session enabled.</param>
        /// <param name="userIdentityName">The user identity name for the current user.</param>
        /// <param name="userSessionData">The session state data for the user.</param>
        public UserOnlineController(bool isActive, string userIdentityName, Object userSessionData)
        {
            if (userIdentityName == null)
            {
                throw new ArgumentNullException("userIdentityName");
            }

            _isActive         = isActive;
            _userSessionData  = userSessionData;
            _userIdentityName = userIdentityName;
            _uniqueHashcode   = Hashcode.GetHashcode(userIdentityName, HashcodeType.SHA512);
        }
コード例 #2
0
ファイル: Membership.cs プロジェクト: waffle-iron/nequeo
        private void OnAuthenticateRequest(object sender, EventArgs e)
        {
            HttpApplication application = (HttpApplication)sender;
            HttpContext     context     = application.Context;
            HttpRequest     request     = context.Request;
            HttpResponse    response    = context.Response;

            try
            {
                // Create a new member info type.
                MemberInfo memberInfo = new MemberInfo();

                // Has the user been authenticated
                if (request.IsAuthenticated)
                {
                    // Get the user identity name
                    string userIdentityName = context.User.Identity.Name;

                    // Generate the hash code from the user identity name.
                    memberInfo.UniqueHashcode   = Hashcode.GetHashcode(userIdentityName, HashcodeType.SHA512);
                    memberInfo.UserIdentityName = userIdentityName;

                    // Add the member info to the context collection.
                    if (((MemberInfo)context.Items[memberInfo.UniqueHashcode]) == null)
                    {
                        context.Items.Add(memberInfo.UniqueHashcode, memberInfo);
                    }

                    // Add the new item or set the current member info.
                    Nequeo.Caching.RuntimeCache.Set(memberInfo.UniqueHashcode, memberInfo, (double)600.0);
                }
                else
                {
                    // The user has not been authenticated
                    // the connecting user is anonymous.
                    string userIdentityName = request.AnonymousID;

                    // If no anonymous id is found then
                    // generate a random user idnetity name.
                    if (String.IsNullOrEmpty(userIdentityName))
                    {
                        LowerUpperCaseGenerator password = new LowerUpperCaseGenerator();
                        userIdentityName           = password.Random(30, 30);
                        memberInfo.IsAnonymousUser = true;
                        memberInfo.HasAnonymousID  = false;
                    }
                    else
                    {
                        memberInfo.IsAnonymousUser = true;
                    }

                    // Generate the hash code from the user identity name.
                    memberInfo.UniqueHashcode   = Hashcode.GetHashcode(userIdentityName, HashcodeType.SHA512);
                    memberInfo.UserIdentityName = userIdentityName;

                    // Add the member info to the context collection.
                    if (((MemberInfo)context.Items[memberInfo.UniqueHashcode]) == null)
                    {
                        context.Items.Add(memberInfo.UniqueHashcode, memberInfo);
                    }

                    // Add the new item or set the current member info.
                    Nequeo.Caching.RuntimeCache.Set(memberInfo.UniqueHashcode, memberInfo, (double)600.0);
                }
            }
            catch (Exception ex)
            {
                context.AddError(ex);
                LogHandler.WriteTypeMessage(ex.Message, typeof(Membership).GetMethod("OnAuthenticateRequest"));
            }
        }