logo
Welcome to our new AbleCommerce forums. As a guest, you may view the information here. To post to this forum, you must have a registered account with us, either as a new user evaluating AbleCommerce or an existing user of the application. For all questions related to the older version of Gold and earlier, please go to AbleCommerce Gold forum. Please use your AbleCommerce username and password to Login. New Registrations are disabled.

Notification

Icon
Error

Options
Go to last post Go to first unread
Joe Payne2  
#1 Posted : Tuesday, October 6, 2020 10:05:04 AM(UTC)
Joe Payne2

Rank: Advanced Member

Groups: HelpDesk, Developers
Joined: 11/9/2018(UTC)
Posts: 564

Thanks: 122 times
Was thanked: 26 time(s) in 25 post(s)
I'm trying to find the best way to force an affiliate value on only the shopper-side pages. If no affiliate is detected, redirect to a landing page.

I thought global.asax Begin_Request() was a good place to work but it's not going as planned.

Any suggestions?

Wanna join the discussion?! Login to your AbleCommerce Forums forum account. New Registrations are disabled.

Naveed Ashraf  
#2 Posted : Wednesday, October 7, 2020 7:59:15 AM(UTC)
Naveed Ashraf

Rank: Advanced Member

Groups: Admin, Administrators, Developers, Registered, HelpDesk, Authorized User
Joined: 7/31/2019(UTC)
Posts: 77

Was thanked: 8 time(s) in 8 post(s)
Global.asax Begin_Request() seems a good place to handle any affiliate related processing. Please explain what issues you are facing with it?


You can check for an affiliate indicator in query string as under:

Code:
// look for an affiliate indicator in the querystring
Store store = AbleContext.Current.Store;
Affiliate affiliate = null;
int affiliateId = AlwaysConvert.ToInt(context.Request.QueryString[store.Settings.AffiliateParameterName]);
if (affiliateId > 0)
   affiliate = AbleContext.Container.Resolve<IAffiliateRepository>().Load(affiliateId);




Please keep in mind that the affiliate related processing can only be done once user instance is initialized. So, you should place the following check around any such code:
Code:

if (AbleContext.Current.User != null)
{

// any affiliate related processing.

}


Thanks for your support!
Naveed Ashraf
Ablecommerce.com
Developer Assistance Available
Joe Payne2  
#3 Posted : Wednesday, October 7, 2020 8:05:09 AM(UTC)
Joe Payne2

Rank: Advanced Member

Groups: HelpDesk, Developers
Joined: 11/9/2018(UTC)
Posts: 564

Thanks: 122 times
Was thanked: 26 time(s) in 25 post(s)
Once I detect that I need to redirect to a no-affiliate page, I ran into a too-many-redirects problem. Since I was using BeginRequest(), it fires both for the initial request and the redirected page. So it just kept redirectly.

I tried using a session variable to toggle a flag I could test for at the beginning of PageRequest(), but I don't think session variables are available consistently in BeginRequest()

I did find an alternate solution in StackOverflow that seems to be working so far. The User context seems populated too at this point, so that concern is handled I think.

First time I've ever seen this method used in Global.asax lol

Code:

        protected void Application_AcquireRequestState(Object sender, EventArgs e)
        {
            if (HttpContext.Current != null && HttpContext.Current.Session != null)
            {
                // don't redirect for admin users
                if (!AbleContext.Current.User.IsAdmin)
                {
                    // don't redirect admin pages
                    string origPath = Request.Path.ToLowerInvariant();
                    if (!origPath.Contains("/admin/"))
                    {

                        // only redirect if no affiliate assigned
                        if (AbleContext.Current.User.Affiliate == null)
                        {
                            bool redirected = false;
                            var beingredirected = HttpContext.Current.Session["beingredirected"];
                            if (beingredirected != null)
                            {
                                redirected = Boolean.Parse(beingredirected.ToString());
                            }

                            if (!redirected)
                            {
                                if (Request.HttpMethod == "GET")
                                {
                                    HttpContext.Current.Session["beingredirected"] = "true";
                                    Response.Redirect("~/No-Affiliate");
                                }
                                else if (Request.HttpMethod == "POST")
                                {
                                }
                            }

                        }

                    }
                }

                HttpContext.Current.Session["beingredirected"] = "false";
            }
        }

Naveed Ashraf  
#4 Posted : Wednesday, October 7, 2020 8:47:35 AM(UTC)
Naveed Ashraf

Rank: Advanced Member

Groups: Admin, Administrators, Developers, Registered, HelpDesk, Authorized User
Joined: 7/31/2019(UTC)
Posts: 77

Was thanked: 8 time(s) in 8 post(s)
Hi Joe,

Instead using a session variable to toggle a flag, it seems that you should just add a new check to exclude the "/No-Affiliate" page from the redirect processing.

something like:

Code:
if (origPath.Contains("/no-affiliate")) return;

Edited by user Wednesday, October 7, 2020 8:48:12 AM(UTC)  | Reason: Not specified

Thanks for your support!
Naveed Ashraf
Ablecommerce.com
Developer Assistance Available
thanks 1 user thanked Naveed Ashraf for this useful post.
Joe Payne2 on 10/7/2020(UTC)
Users browsing this topic
Guest (2)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.