Exemplo n.º 1
0
        public static HiContext Create(HttpContext context, bool isReWritten)
        {
            HiContext context2 = new HiContext(context)
            {
                IsUrlReWritten = isReWritten
            };

            SaveContextToStore(context2);
            return(context2);
        }
Exemplo n.º 2
0
        public static HiContext Create(HttpContext context, UrlReWriterDelegate rewriter)
        {
            HiContext context2 = new HiContext(context);

            SaveContextToStore(context2);
            if (null != rewriter)
            {
                context2.IsUrlReWritten = rewriter(context);
            }
            return(context2);
        }
Exemplo n.º 3
0
        public static bool UpdateDistributor(IUser user)
        {
            if (null == user)
            {
                return(false);
            }
            bool flag = UserHelper.UpdateUser(user.MembershipUser);

            if (flag)
            {
                flag = DistributorFactory.Instance().UpdateUser(user);
                HiContext current = HiContext.Current;
                if (current.User.UserId == user.UserId)
                {
                    current.User = user;
                }
            }
            ClearUserCache(user);
            return(flag);
        }
Exemplo n.º 4
0
        private void Application_AuthorizeRequest(object source, EventArgs e)
        {
            if (this.currentApplicationType != ApplicationType.Installer)
            {
                HttpApplication application = (HttpApplication)source;
                HttpContext     context     = application.Context;
                HiContext       current     = HiContext.Current;


                if (context.Request.IsAuthenticated)
                {
                    string name = context.User.Identity.Name;
                    if (name != null)
                    {
                        string[] rolesForUser = Roles.GetRolesForUser(name);
                        if ((rolesForUser != null) && (rolesForUser.Length > 0))
                        {
                            current.RolesCacheKey = string.Join(",", rolesForUser);
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        private void Application_BeginRequest(object source, EventArgs e)
        {
            this.currentApplicationType = HiConfiguration.GetConfig().AppLocation.CurrentApplicationType;
            HttpApplication application = (HttpApplication)source;
            HttpContext     context     = application.Context;

            if (context.Request.RawUrl.IndexOfAny(new char[] { '<', '>', '\'', '"' }) != -1)
            {
                context.Response.Redirect(
                    context.Request.RawUrl.Replace("<", "%3c")
                    .Replace(">", "%3e")
                    .Replace("'", "%27")
                    .Replace("\"", "%22"), false);
            }
            else
            {
                this.CheckInstall(context);
                if (this.currentApplicationType != ApplicationType.Installer)
                {
                    CheckSSL(HiConfiguration.GetConfig().SSL, context);
                    HiContext.Create(context, new UrlReWriterDelegate(HiHttpModule.ReWriteUrl));
                    if (HiContext.Current.SiteSettings.IsDistributorSettings &&
                        !((!HiContext.Current.SiteSettings.Disabled ||
                           (this.currentApplicationType != ApplicationType.Common)) ||
                          urlReg.IsMatch(context.Request.Url.AbsolutePath)))
                    {
                        context.Response.Write("站点维护中,暂停访问!");
                        context.Response.End();
                    }
                }
            }

            #region MyRegion by yongjin.C
            try
            {
                String SessionKey = context.Request.QueryString["SessionKey"];
                if (SessionKey == null)
                {
                    SessionKey = context.Request.Cookies["SSOSessionKey"] == null ? null : context.Request.Cookies["SSOSessionKey"].Value;
                }
                if (!String.IsNullOrEmpty(SessionKey) && SessionKey.ToLower() != "null")
                {
                    String AppKey      = ConfigurationManager.AppSettings["AppKey"];
                    String SSOPassport = ConfigurationManager.AppSettings["SSOPassport"];

                    String url;

                    //去掉端口号
                    if (HttpContext.Current.Request.Url.ToString().ToLower().IndexOf("localhost") > -1)
                    {
                        url = context.Request.Url.ToString();
                    }
                    else
                    {
                        url = "http://" + HttpContext.Current.Request.Url.Host + HttpContext.Current.Request.Url.PathAndQuery;
                    }
                    log.GetInstance().writeLog(AppKey + "-*-" + SessionKey + "-*-" + url);
                    String info = CheckLogin(AppKey, SessionKey);
                    log.GetInstance().writeLog(info);
                    String[] infoarray = info.Split('&');
                    if (!String.IsNullOrEmpty(info) && infoarray.Length == 2)
                    {
                        var sessionUserInfo = HttpContext.Current.Request.Cookies["SessionUserInfo"];
                        if (sessionUserInfo != null)
                        {
                            sessionUserInfo.Value         = HttpUtility.UrlEncode(infoarray[0]);
                            sessionUserInfo["SessionKey"] = SessionKey;
                            sessionUserInfo["defer"]      = infoarray[1];
                            HttpContext.Current.Response.AppendCookie(sessionUserInfo);
                        }
                        else
                        {
                            HttpCookie nCookie = new HttpCookie("SessionUserInfo", HttpUtility.UrlEncode(infoarray[0]));
                            nCookie["SessionKey"] = SessionKey;
                            nCookie["defer"]      = infoarray[1];
                            HttpContext.Current.Response.Cookies.Add(nCookie);
                        }

                        //过滤SessionKey
                        url = fiterUrl(url, "SessionKey");
                        url = fiterUrl(url, "from");
                        String        from = HttpContext.Current.Request.QueryString["from"];
                        StringBuilder rurl = new StringBuilder("/SSO.aspx?login=1");
                        if (!String.IsNullOrEmpty(from))
                        {
                            rurl.Append("&from=" + from);
                        }
                        rurl.Append("&returnurl=" +
                                    HttpUtility.UrlEncode(url,
                                                          Encoding.UTF8));
                        HttpContext.Current.Response.Redirect(rurl.ToString(), true);
                        return;
                    }
                    else if (String.IsNullOrEmpty(info))
                    {
                        log.blog = true;
                        log.GetInstance().writeLog("用户为空");
                        url = fiterUrl(url, "SessionKey");
                        //过滤SessionKey
                        url = fiterUrl(url, "from");
                        HttpContext.Current.Response.Redirect(
                            string.Format("{0}/Passport/login?appkey={1}&redirectUrl={2}",
                                          SSOPassport.Trim('/'), AppKey, HttpUtility.UrlEncode(url,
                                                                                               Encoding.UTF8)), false);
                        return;
                    }
                }
                else
                {
                    var sessionUserInfo = HttpContext.Current.Request.Cookies["SessionUserInfo"];

                    //  var cookieSession = HttpContext.Current.Request.Cookies["SessionKey"];
                    if (sessionUserInfo != null &&
                        DateTime.Now.AddMinutes(5) >= Convert.ToDateTime(sessionUserInfo["defer"]))
                    {
                        // 定时延期 延期
                        String AppKey = ConfigurationManager.AppSettings["AppKey"];
                        String defer  = null;
                        string r      = toKeepSessionKey(AppKey, sessionUserInfo["SessionKey"]);
                        if (!string.IsNullOrEmpty(r))
                        {
                            var ar = r.Split('&');
                            if (ar.Length == 2)
                            {
                                defer = ar[1];
                            }
                        }
                        if (!string.IsNullOrEmpty(defer))
                        {
                            sessionUserInfo["defer"] = defer; //设置过期时间有问题
                        }
                        HttpContext.Current.Response.AppendCookie(sessionUserInfo);
                    }
                }
            }
            catch (Exception ex)
            {
                log.blog = true;
                log.GetInstance().writeLog(ex.Message);
            }

            #endregion
        }
Exemplo n.º 6
0
 private static void SaveContextToStore(HiContext context)
 {
     context.Context.Items["ExhibFlat_ContextStore"] = context;
 }