Esempio n. 1
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Tracks an Anonymous User
        /// </summary>
        /// <param name="context">An HttpContext Object</param>
        /// -----------------------------------------------------------------------------
        private void TrackAnonymousUser(HttpContext context)
        {
            string cookieName     = "DotNetNukeAnonymous";
            var    portalSettings = (PortalSettings)context.Items["PortalSettings"];

            if (portalSettings == null)
            {
                return;
            }
            AnonymousUserInfo user;
            Hashtable         userList = GetUserList();
            string            userID;

            //Check if the Tracking cookie exists
            HttpCookie cookie = context.Request.Cookies[cookieName];

            //Track Anonymous User
            if ((cookie == null))
            {
                //Create a temporary userId
                userID = Guid.NewGuid().ToString();

                //Create a new cookie
                cookie = new HttpCookie(cookieName, userID)
                {
                    Expires = DateTime.Now.AddMinutes(20),
                    Path    = (!string.IsNullOrEmpty(Globals.ApplicationPath) ? Globals.ApplicationPath : "/")
                };
                context.Response.Cookies.Add(cookie);

                //Create a user
                user = new AnonymousUserInfo
                {
                    UserID         = userID,
                    PortalID       = portalSettings.PortalId,
                    TabID          = portalSettings.ActiveTab.TabID,
                    CreationDate   = DateTime.Now,
                    LastActiveDate = DateTime.Now
                };

                //Add the user
                if (!userList.Contains(userID))
                {
                    userList[userID] = user;
                }
            }
            else
            {
                if ((cookie.Value == null))
                {
                    //Expire the cookie, there is something wrong with it
                    context.Response.Cookies[cookieName].Expires = new DateTime(1999, 10, 12);

                    //No need to do anything else
                    return;
                }

                //Get userID out of cookie
                userID = cookie.Value;

                //Find the cookie in the user list
                if ((userList[userID] == null))
                {
                    userList[userID] = new AnonymousUserInfo();
                    ((AnonymousUserInfo)userList[userID]).CreationDate = DateTime.Now;
                }

                user                = (AnonymousUserInfo)userList[userID];
                user.UserID         = userID;
                user.PortalID       = portalSettings.PortalId;
                user.TabID          = portalSettings.ActiveTab.TabID;
                user.LastActiveDate = DateTime.Now;

                //Reset the expiration on the cookie
                cookie = new HttpCookie(cookieName, userID)
                {
                    Expires = DateTime.Now.AddMinutes(20),
                    Path    = (!string.IsNullOrEmpty(Globals.ApplicationPath) ? Globals.ApplicationPath : "/")
                };
                context.Response.Cookies.Add(cookie);
            }
        }
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Tracks an Anonymous User
        /// </summary>
        /// <param name="context">An HttpContext Object</param>
        /// <history>
        ///     [cnurse]	03/14/2006	documented
        /// </history>
        /// -----------------------------------------------------------------------------
        private void TrackAnonymousUser(HttpContext context)
        {
            string cookieName = "DotNetNukeAnonymous";
            var portalSettings = (PortalSettings) context.Items["PortalSettings"];
            if (portalSettings == null)
            {
                return;
            }
            AnonymousUserInfo user;
            Hashtable userList = GetUserList();
            string userID;

            //Check if the Tracking cookie exists
            HttpCookie cookie = context.Request.Cookies[cookieName];
            //Track Anonymous User
			if ((cookie == null))
            {  	
                //Create a temporary userId
                userID = Guid.NewGuid().ToString();

                //Create a new cookie
                cookie = new HttpCookie(cookieName);
                cookie.Value = userID;
                cookie.Expires = DateTime.Now.AddMinutes(20);
                context.Response.Cookies.Add(cookie);

                //Create a user
                user = new AnonymousUserInfo();
                user.UserID = userID;
                user.PortalID = portalSettings.PortalId;
                user.TabID = portalSettings.ActiveTab.TabID;
                user.CreationDate = DateTime.Now;
                user.LastActiveDate = DateTime.Now;

                //Add the user
                if (!userList.Contains(userID))
                {
                    userList[userID] = user;
                }
            }
            else
            {
                if ((cookie.Value == null))
                {
					//Expire the cookie, there is something wrong with it
                    context.Response.Cookies[cookieName].Expires = new DateTime(1999, 10, 12);

                    //No need to do anything else
                    return;
                }
				
                //Get userID out of cookie
                userID = cookie.Value;

                //Find the cookie in the user list
                if ((userList[userID] == null))
                {
                    userList[userID] = new AnonymousUserInfo();
                    ((AnonymousUserInfo) userList[userID]).CreationDate = DateTime.Now;
                }
				
                user = (AnonymousUserInfo) userList[userID];
                user.UserID = userID;
                user.PortalID = portalSettings.PortalId;
                user.TabID = portalSettings.ActiveTab.TabID;
                user.LastActiveDate = DateTime.Now;

                //Reset the expiration on the cookie
                cookie = new HttpCookie(cookieName);
                cookie.Value = userID;
                cookie.Expires = DateTime.Now.AddMinutes(20);
                context.Response.Cookies.Add(cookie);
            }
        }