Exemplo n.º 1
0
        public static string AppendSessionID(RequestContext requestContext, string url)
        {
            try
            {
                MobiContext paywallContext = MobiContext.GetCurrent(requestContext.HttpContext.ApplicationInstance.Context);
                string      sessionID      = paywallContext.Session.SessionData.Guid.ToString().Replace("-", "");
                string      sessionPath    = MobiChat.Constants.SessionID + "/" + sessionID;

                if (url.Contains(MobiChat.Constants.SessionID + "/"))
                {
                    if (url.Contains(sessionPath))
                    {
                        //INFO: Session in URL matches session in context.
                        //Log.Debug(new LogMessageBuilder(new PaywallLogErrorCode("web.core", "urlhelper", "match"),
                        //  string.Format("SessionID in URL ({0}) matches SessionID ({1}) from context.", url, sessionID)));
                        return(url);
                    }
                    else
                    {
                        //INFO: Session in URL does NOT match session in context.
                        //Log.Debug(new LogMessageBuilder(new PaywallLogErrorCode("web.core", "urlhelper", "match"),
                        //  string.Format("SessionID in URL ({0}) does NOT match SessionID ({1}) from context.", url, sessionID)));
                        return("/");
                    }
                }
                else
                {
                    //INFO: Session is not provided in URL. So append it.
                    //Log.Debug(new LogMessageBuilder(new PaywallLogErrorCode("web.core", "urlhelper", "notprovided"),
                    //    string.Format("SessionID is not provided in URL ({0}). SessionID ({1}) from context will be appended to URL.", url, sessionID)));
                    url = PrepareUrl(url, sessionPath);
                }

                if (!url.StartsWith("/"))
                {
                    url = "/" + url;
                }

                //Log.Debug(new LogMessageBuilder(new PaywallLogErrorCode("web.core", "urlhelper", "end"),
                //    string.Format("Final URL ({0})", url)));
            }
            catch (Exception e)
            {
                // TODO log this error
                Log.Error("URL in UrlHelper is not correct.", e);
            }

            return(url);
        }
Exemplo n.º 2
0
        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, WebApplication.GetRuntime(httpContext));
                httpContext.Items[MobiHttpContextItemKey] = mobiContext;
                return(mobiContext);
            }
        }
Exemplo n.º 3
0
        protected virtual void Application_PreRequestHandlerExecute(object sender, EventArgs e)
        {
            //IPaywallRuntime runtime = PaywallHttpApplication.GetRuntime(this);
            HttpContext httpContext = HttpContext.Current;

            if (HttpContext.Current.Session == null)
            {
                return;
            }

            //if (HttpContext.Current.Handler == null || HttpContext.Current.Session == null ||
            //		HttpContext.Current.Handler.GetType().IsAssignableFrom(typeof(IRequiresSessionState)))
            //	return;

            MobiContext mobiContext = MobiContext.Current;

            return;
        }
Exemplo n.º 4
0
        public static string AppendSessionID(string url)
        {
            MobiContext mobiContext = Current;
            string      sessionID   = mobiContext.Session.SessionData.Guid.ToString().Replace("-", "");
            string      sessionPath = MobiChat.Constants.SessionID + "/" + sessionID;

            if (url.Contains(MobiChat.Constants.SessionID + "/"))
            {
                if (url.Contains(sessionPath))
                {
                    //INFO: Session in URL matches session in context.
                    //Log.Debug(new LogMessageBuilder(new PaywallLogErrorCode("web.core", "urlhelper", "match"),
                    //  string.Format("SessionID in URL ({0}) matches SessionID ({1}) from context.", url, sessionID)));
                    Log.Info("Session in URL matches session in context.");
                    return(url);
                }
                else
                {
                    //INFO: Session in URL does NOT match session in context.
                    //Log.Debug(new LogMessageBuilder(new PaywallLogErrorCode("web.core", "urlhelper", "match"),
                    //  string.Format("SessionID in URL ({0}) does NOT match SessionID ({1}) from context.", url, sessionID)));
                    Log.Info("Session in URL does NOT match session in context");
                    return("/");
                }
            }
            else
            {
                //INFO: Session is not provided in URL. So append it.
                //Log.Debug(new LogMessageBuilder(new PaywallLogErrorCode("web.core", "urlhelper", "notprovided"),
                //    string.Format("SessionID is not provided in URL ({0}). SessionID ({1}) from context will be appended to URL.", url, sessionID)));
                Log.Info("Session is not provided in URL. So append it.");
                url = PrepareUrl(url, sessionPath);
            }

            if (!url.StartsWith("/"))
            {
                url = "/" + url;
            }

            //Log.Debug(new LogMessageBuilder(new PaywallLogErrorCode("web.core", "urlhelper", "end"),
            //    string.Format("Final URL ({0})", url)));
            return(url);
        }
Exemplo n.º 5
0
 public MobiViewModelBase(MobiContext context)
 {
     this._mobiContext = context;
 }