Beispiel #1
0
        protected void Redirect()
        {
            RedirectController       redirCtrl      = new RedirectController();
            ArrayList                redirectsRef   = redirCtrl.GetRedirectsRef(ModuleId);
            ArrayList                redirects      = redirCtrl.GetRedirects(PortalId, ModuleId);
            List <RedirectInfoParam> redirectsParam = redirCtrl.GetRedirectsParam(ModuleId);

            ModuleController modCtrl = new ModuleController();
            //Hashtable modSettings = modCtrl.GetModuleSettings(ModuleId);
            var module      = modCtrl.GetModule(ModuleId);
            var modSettings = module.ModuleSettings;

            string redirUrl = null;

            bool bLogout;

            try {
                bLogout = Convert.ToBoolean(modSettings["LogoutUser"].ToString());
            } catch { bLogout = false; }

            // check parameters
            foreach (RedirectInfoParam redInfo in redirectsParam)
            {
                NameValueCollection collection = null;
                switch (redInfo.ParamType)
                {
                case RedirectInfoParam.eParamType.GET:
                    collection = Request.QueryString;
                    break;

                case RedirectInfoParam.eParamType.POST:
                    collection = Request.Form;
                    break;

                case RedirectInfoParam.eParamType.GET_POST:
                    collection = Request.Params;
                    break;
                }

                if (collection == null)
                {
                    continue;
                }

                // check if matches

                bool   bMatch     = false;
                string paramName  = Tokenize(redInfo.Param);
                string paramValue = Tokenize(redInfo.Value);

                if (collection[paramName] == null)
                {
                    if (redInfo.Operation == RedirectInfoParam.eOperation.NotExists)
                    {
                        bMatch = true;
                    }
                    else
                    {
                        continue;
                    }
                }
                else
                {
                    if (redInfo.Operation == RedirectInfoParam.eOperation.Exists)
                    {
                        bMatch = true;
                    }
                }

                if (bMatch == false)
                {
                    switch (redInfo.Operation)
                    {
                    case RedirectInfoParam.eOperation.Equals:
                        if (paramValue == collection[paramName])
                        {
                            bMatch = true;
                        }
                        break;

                    case RedirectInfoParam.eOperation.NotEquals:
                        if (paramValue != collection[paramName])
                        {
                            bMatch = true;
                        }
                        break;

                    case RedirectInfoParam.eOperation.Contains:
                        if (collection[paramName].Contains(paramValue))
                        {
                            bMatch = true;
                        }
                        break;

                    case RedirectInfoParam.eOperation.NotContains:
                        if (!collection[paramName].Contains(paramValue))
                        {
                            bMatch = true;
                        }
                        break;
                    }
                }

                if (bMatch)
                {
                    redirUrl = redInfo.RedirectUrl;
                    bLogout  = redInfo.LogoutUser;
                    if (string.IsNullOrEmpty(redirUrl))
                    {
                        CheckLogout(bLogout);
                        return; // keep on page
                    }
                    break;
                }
            }

            // check referrers first
            if (redirUrl == null)
            {
                string urlReferrer = "";
                if (Request.UrlReferrer != null && !string.IsNullOrEmpty(Request.UrlReferrer.ToString()))
                {
                    urlReferrer = Request.UrlReferrer.ToString();
                }

                foreach (RedirectRefInfo redInfo in redirectsRef)
                {
                    string checkRef = Tokenize(redInfo.Referrer);

                    if (redInfo.MatchDomainOnly)
                    {
                        if (urlReferrer.IndexOf(checkRef) == 0)
                        {
                            redirUrl = redInfo.RedirectUrl;
                            if (string.IsNullOrEmpty(redirUrl))
                            {
                                CheckLogout(bLogout);
                                return; // keep on page
                            }
                            break;
                        }
                    }
                    else
                    {
                        if (checkRef == urlReferrer)
                        {
                            redirUrl = redInfo.RedirectUrl;
                            if (string.IsNullOrEmpty(redirUrl))
                            {
                                CheckLogout(bLogout);
                                return; // keep on page
                            }
                            break;
                        }
                    }
                }
            }

            // check which one matches
            if (redirUrl == null)
            {
                foreach (RedirectInfo redInfo in redirects)
                {
                    if (redInfo.RoleId > 0)
                    {
                        if (UserInfo.IsInRole(redInfo.RoleName))
                        {
                            redirUrl = redInfo.RedirectUrl;
                            bLogout  = redInfo.LogoutUser;
                            if (string.IsNullOrEmpty(redirUrl))
                            {
                                CheckLogout(bLogout);
                                return; // keep on page
                            }
                            break;
                        }
                    }
                    else
                    {
                        if (redInfo.RoleUnregisteredUsers && UserInfo.UserID <= 0)
                        {
                            redirUrl = redInfo.RedirectUrl;
                            bLogout  = redInfo.LogoutUser;
                            if (string.IsNullOrEmpty(redirUrl))
                            {
                                CheckLogout(bLogout);
                                return; // keep on page
                            }
                            break;
                        }
                        else if (redInfo.RoleAllUsers)
                        {
                            redirUrl = redInfo.RedirectUrl;
                            bLogout  = redInfo.LogoutUser;
                            if (string.IsNullOrEmpty(redirUrl))
                            {
                                CheckLogout(bLogout);
                                return; // keep on page
                            }
                            break;
                        }
                    }
                }
            }

            // see if we have get param
            if (redirUrl == null)
            {
                if (modSettings.ContainsKey("GetParam") && modSettings["GetParam"].ToString().Length > 0)
                {
                    if (!String.IsNullOrEmpty(Request.QueryString[modSettings["GetParam"].ToString()]))
                    {
                        redirUrl = Request.QueryString[modSettings["GetParam"].ToString()];
                    }
                }
            }

            if (redirUrl == null)
            {
                if (modSettings.ContainsKey("GetParamRef") && modSettings["GetParamRef"].ToString().Length > 0)
                {
                    try {
                        Match m = Regex.Match(Request.UrlReferrer.ToString(), modSettings["GetParamRef"].ToString() + "=([^&]+)");
                        if (!String.IsNullOrEmpty(m.Groups[1].Captures[0].Value))
                        {
                            redirUrl = m.Groups[1].Captures[0].Value;
                        }
                    } catch {
                    }
                }
            }

            // we're up to default url
            if (redirUrl == null)
            {
                if (modSettings.ContainsKey("DefaultUrl") && modSettings["DefaultUrl"].ToString().Length > 0)
                {
                    redirUrl = modSettings["DefaultUrl"].ToString();
                }
            }

            if (redirUrl == null)
            {
                // redirect failed
                //pnlRedirectUser.Visible = true;
                //pnlRedirectUser.InnerHtml = "<b>Redirect Failed!<b/><br/><br/>There is no redirect defined for current role.";
                CheckLogout(bLogout);
                return;
            }

            redirUrl = redirUrl.Trim();

            // apply tokens
            redirUrl = Tokenize(redirUrl);


            CheckLogout(bLogout);

            Response.Redirect(redirUrl);
        }
        protected void Redirect()
        {
            RedirectController redirCtrl = new RedirectController();
            ArrayList redirectsRef = redirCtrl.GetRedirectsRef(ModuleId);
            ArrayList redirects = redirCtrl.GetRedirects(PortalId, ModuleId);
            List<RedirectInfoParam> redirectsParam = redirCtrl.GetRedirectsParam(ModuleId);

            ModuleController modCtrl = new ModuleController();
            Hashtable modSettings = modCtrl.GetModuleSettings(ModuleId);

            string redirUrl = null;

            bool bLogout;
            try {
                bLogout = Convert.ToBoolean(modCtrl.GetModuleSettings(ModuleId)["LogoutUser"].ToString());
            } catch { bLogout = false; }

            // check parameters
            foreach (RedirectInfoParam redInfo in redirectsParam) {

                NameValueCollection collection = null;
                switch (redInfo.ParamType) {
                    case RedirectInfoParam.eParamType.GET:
                        collection = Request.QueryString;
                        break;
                    case RedirectInfoParam.eParamType.POST:
                        collection = Request.Form;
                        break;
                    case RedirectInfoParam.eParamType.GET_POST:
                        collection = Request.Params;
                        break;
                }

                if (collection == null)
                    continue;

                // check if matches

                bool bMatch = false;
                string paramName = Tokenize(redInfo.Param);
                string paramValue =Tokenize(redInfo.Value);

                if (collection[paramName] == null) {
                    if (redInfo.Operation == RedirectInfoParam.eOperation.NotExists) {
                        bMatch = true;
                    } else { continue; }
                } else {
                    if (redInfo.Operation == RedirectInfoParam.eOperation.Exists) {
                        bMatch = true;
                    }
                }

                if (bMatch == false) {
                    switch (redInfo.Operation) {
                        case RedirectInfoParam.eOperation.Equals:
                            if (paramValue == collection[paramName])
                                bMatch = true;
                            break;
                        case RedirectInfoParam.eOperation.NotEquals:
                            if (paramValue != collection[paramName])
                                bMatch = true;
                            break;
                        case RedirectInfoParam.eOperation.Contains:
                            if (collection[paramName].Contains(paramValue))
                                bMatch = true;
                            break;
                        case RedirectInfoParam.eOperation.NotContains:
                            if (!collection[paramName].Contains(paramValue))
                                bMatch = true;
                            break;
                    }
                }

                if (bMatch) {
                    redirUrl = redInfo.RedirectUrl;
                    bLogout = redInfo.LogoutUser;
                    if (string.IsNullOrEmpty(redirUrl)) {
                        CheckLogout(bLogout);
                        return; // keep on page
                    }
                    break;
                }
            }

            // check referrers first
            if (redirUrl == null) {
                string urlReferrer = "";
                if (Request.UrlReferrer != null && !string.IsNullOrEmpty(Request.UrlReferrer.ToString())) {
                    urlReferrer = Request.UrlReferrer.ToString();
                }

                foreach (RedirectRefInfo redInfo in redirectsRef) {

                    string checkRef = Tokenize(redInfo.Referrer);

                    if (redInfo.MatchDomainOnly) {
                        if (urlReferrer.IndexOf(checkRef) == 0) {
                            redirUrl = redInfo.RedirectUrl;
                            if (string.IsNullOrEmpty(redirUrl)) {
                                CheckLogout(bLogout);
                                return; // keep on page
                            }
                            break;
                        }
                    } else {
                        if (checkRef == urlReferrer) {
                            redirUrl = redInfo.RedirectUrl;
                            if (string.IsNullOrEmpty(redirUrl)) {
                                CheckLogout(bLogout);
                                return; // keep on page
                            }
                            break;
                        }
                    }
                }
            }

            // check which one matches
            if (redirUrl == null) {
                foreach (RedirectInfo redInfo in redirects) {
                    if (redInfo.RoleId > 0) {
                        if (UserInfo.IsInRole(redInfo.RoleName)) {
                            redirUrl = redInfo.RedirectUrl;
                            bLogout = redInfo.LogoutUser;
                            if (string.IsNullOrEmpty(redirUrl)) {
                                CheckLogout(bLogout);
                                return; // keep on page
                            }
                            break;
                        }
                    } else {
                        if (redInfo.RoleUnregisteredUsers && UserInfo.UserID <= 0) {
                            redirUrl = redInfo.RedirectUrl;
                            bLogout = redInfo.LogoutUser;
                            if (string.IsNullOrEmpty(redirUrl)) {
                                CheckLogout(bLogout);
                                return; // keep on page
                            }
                            break;
                        } else if (redInfo.RoleAllUsers) {
                            redirUrl = redInfo.RedirectUrl;
                            bLogout = redInfo.LogoutUser;
                            if (string.IsNullOrEmpty(redirUrl)) {
                                CheckLogout(bLogout);
                                return; // keep on page
                            }
                            break;
                        }
                    }
                }
            }

            // see if we have get param
            if (redirUrl == null) {
                if (modSettings.ContainsKey("GetParam") && modSettings["GetParam"].ToString().Length > 0) {
                    if (!String.IsNullOrEmpty(Request.QueryString[modSettings["GetParam"].ToString()])) {
                        redirUrl = Request.QueryString[modSettings["GetParam"].ToString()];
                    }
                }
            }

            if (redirUrl == null) {
                if (modSettings.ContainsKey("GetParamRef") && modSettings["GetParamRef"].ToString().Length > 0) {
                    try {
                        Match m = Regex.Match(Request.UrlReferrer.ToString(), modSettings["GetParamRef"].ToString() + "=([^&]+)");
                        if (!String.IsNullOrEmpty(m.Groups[1].Captures[0].Value)) {
                            redirUrl = m.Groups[1].Captures[0].Value;
                        }
                    } catch {
                    }
                }
            }

            // we're up to default url
            if (redirUrl == null) {
                if (modSettings.ContainsKey("DefaultUrl") && modSettings["DefaultUrl"].ToString().Length > 0) {
                    redirUrl = modSettings["DefaultUrl"].ToString();
                }
            }

            if (redirUrl == null) {
                // redirect failed
                //pnlRedirectUser.Visible = true;
                //pnlRedirectUser.InnerHtml = "<b>Redirect Failed!<b/><br/><br/>There is no redirect defined for current role.";
                CheckLogout(bLogout);
                return;
            }

            redirUrl = redirUrl.Trim();

            // apply tokens
            redirUrl = Tokenize(redirUrl);

            CheckLogout(bLogout);

            Response.Redirect(redirUrl);
        }