public static MobiContext GetCurrent(HttpContext httpContext) { lock (httpContext.Request) { MobiContext mobiContext = httpContext.Items[MobiHttpContextItemKey] as MobiContext; if (mobiContext != null) { return(mobiContext as MobiContext); } mobiContext = new MobiContext(httpContext, ManagementApplication.GetRuntime(httpContext)); httpContext.Items[MobiHttpContextItemKey] = mobiContext; return(mobiContext); } }
protected virtual void InitializeRuntime() { if (ManagementApplication.HasRuntime(this)) { return; } lock (MobiHttpApplicationInitializeRuntimeLockObject) { //string name = HostingEnvironment.SiteName; if (ManagementApplication.HasRuntime(this)) { return; } this._baseApplication = new ApplicationBase(MobiChat.Data.Application.CreateManager().Load(2)); if (this._baseApplication == null) { //Log.Fatal(new LogMessageBuilder(new LogErrorCode("paywall.web.core", "paywallhttpapplication", "initializeruntime"), // string.Format("Application {0} is not loaded.", HostingEnvironment.SiteName), application)); throw new InvalidOperationException(string.Format("No application with name '{0}' registered in database.", HostingEnvironment.SiteName)); } IRuntime runtime = this._baseApplication.ApplicationData.InstantiateRuntime(); if (!runtime.Initialize(HostingEnvironment.SiteName)) { return; } ManagementApplication.SetRuntime(this, runtime); //Log.Debug(new LogMessageBuilder(new LogErrorCode("paywall.web.core", "paywallhttpapplication", "initialize"), "Application initialized!", application.Name)); // TODO: Fix this // outeConfig.RegisterRoutes(this); this.InitializeApplication(); } //Log.Info(new LogMessageBuilder(new LogErrorCode("paywall.web.core", "paywallhttpapplication", "initializeruntime"), // "Initialization of PaywallHttpApplication(" + HostingEnvironment.SiteName + ") is complete")); return; }
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, ManagementApplication.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 ManagementUserSession(session); }
protected static void SetRuntime(HttpApplication application, IRuntime runtime) { ManagementApplication.SetRuntime(application.Application, runtime); }
protected static void SetRuntime(HttpContext context, IRuntime runtime) { ManagementApplication.SetRuntime(context.Application, runtime); }
public static IRuntime GetRuntime(HttpApplication application) { return(ManagementApplication.GetRuntime(application.Application)); }
public static IRuntime GetRuntime(HttpContext context) { return(ManagementApplication.GetRuntime(context.Application)); }
public static bool HasRuntime(HttpApplication application) { return(ManagementApplication.HasRuntime(application.Application)); }
public static bool HasRuntime(HttpContext context) { return(ManagementApplication.HasRuntime(context.Application)); }