Ejemplo n.º 1
0
        protected virtual void InitializeSession(HttpContext httpContext)
        {
            string sessionID   = httpContext.Session.SessionID;
            Guid   sessionGuid = Guid.Empty;

            if (!Guid.TryParseExact(sessionID, "N", out sessionGuid))
            {
                // TODO: log4net
                //if (Log.IsWarnEnabled)
                //  Log.Warn(new LogMessageBuilder(
                //    new LogErrorCode("paywall.web.core", "paywallhttpcontext", "initializesession"),
                //      "Invalid session ID", sessionGuid));

                throw new ArgumentException("MobiContext: Could not parse Session guid");
            }

            IUserSessionManager usManager = UserSession.CreateManager();
            UserSession         session   = usManager.Load(sessionGuid);

            if (session != null && session.IPAddress != httpContext.Request.UserHostAddress)
            {
                // TODO: Session hijack.. log
            }

            if (session == null)
            {
                IIPCountryMapManager ipcmManager = IPCountryMap.CreateManager();

                // TODO: Remove this in production
                string ipAddress = !httpContext.Request.UserHostAddress.Equals("::1") && !httpContext.Request.UserHostAddress.StartsWith("192.") ?
                                   httpContext.Request.UserHostAddress :
                                   "78.155.61.246";

                IPCountryMap countryMap = ipcmManager.Load(ipAddress);
                Language     language   = countryMap.Country.Language != null ? countryMap.Country.Language : Language.CreateManager().Load("EN", LanguageIdentifier.TwoLetterIsoCode);

                session = new UserSession(-1,
                                          sessionGuid,
                                          StatisticsApplication.GetDefaultUserSessionType(),
                                          null,     // service
                                          this.Runtime.ApplicationData,
                                          null,     // domain,
                                          null,     // user,
                                          countryMap.Country,
                                          language, // language
                                          null,     // mobileOperator
                                          null,     // trackingID,
                                          httpContext.Request.UserHostAddress,
                                          httpContext.Request.UserAgent,
                                          httpContext.Request.Url.ToString().Replace(" ", string.Empty),
                                          httpContext.Request.UrlReferrer != null ? httpContext.Request.UrlReferrer.ToString() : null,
                                          false,
                                          DateTime.Now.AddMinutes(20),
                                          DateTime.Now, DateTime.Now);

                session.Insert();

                //INFO: DO NOT DO ANYTHING WITH THIS LINE BELOW!!!
                httpContext.Session["someValue"] = "bla";
            }

            this._session = new StatisticsUserSession(session);
        }
Ejemplo n.º 2
0
        protected virtual void InitializeSession(HttpContext httpContext)
        {
            string sessionID   = httpContext.Session.SessionID;
            Guid   sessionGuid = Guid.Empty;

            if (!Guid.TryParseExact(sessionID, "N", out sessionGuid))
            {
                Log.Error("Invalid session ID" + sessionGuid);
            }

            IUserSessionManager usManager = UserSession.CreateManager();
            UserSession         session   = usManager.Load(this.Service.ServiceData, sessionGuid);

            if (session != null && session.IPAddress != httpContext.Request.UserHostAddress)
            {
                Log.Error("Session hijack!");
            }

            if (session == null)
            {
                // TODO: Remove this in production
                string ipAddress = !httpContext.Request.UserHostAddress.Equals("::1") && !httpContext.Request.UserHostAddress.StartsWith("192.") ?
                                   httpContext.Request.UserHostAddress :
                                   "78.155.61.246";

                IIPCountryMapManager ipcmManager = IPCountryMap.CreateManager();
                IPCountryMap         countryMap  = ipcmManager.Load(ipAddress);

                Language language = countryMap.Country.Language != null ? countryMap.Country.Language : Language.CreateManager().Load("EN", LanguageIdentifier.TwoLetterIsoCode);

                session = new UserSession(-1,
                                          sessionGuid,
                                          this.Service.ServiceData.UserSessionType,
                                          this.Service.ServiceData,
                                          null,
                                          this.Domain,
                                          null,
                                          countryMap.Country,
                                          language,
                                          null,
                                          null,
                                          httpContext.Request.UserHostAddress,
                                          httpContext.Request.UserAgent,
                                          httpContext.Request.Url.ToString(),
                                          httpContext.Request.UrlReferrer != null ? httpContext.Request.UrlReferrer.ToString() : null,
                                          false,
                                          DateTime.Now.AddMinutes(20),
                                          DateTime.Now, DateTime.Now);

                // TODO: Make this dynamic
                if (!session.EntranceUrl.Contains("/thumbnail") &&
                    !session.EntranceUrl.EndsWith("/logo"))
                {
                    session.Insert();
                }

                //INFO: DO NOT DO ANYTHING WITH THIS LINE BELOW!!!
                httpContext.Session["someValue"] = "bla";
            }

            this._session = new WebUserSession(session);
        }