Welcome to Vortx Community Forum, where you can ask questions and receive answers from the staff at Vortx and other members of the community.

If you had a user account on our previous forums website, you will need to register a new account here.

Learn more about...

AspDotNetStorefront
DotFeed

How do I set anonymous customerid from ajax call into session

I have a form that issues an ajax call that creates a new shopping cart based on user params. If the user is not a customer, I create an ananymous customer within the call and assocated cart items are attached to that customer. How can I take that customer (id?) and get it into session so that when I display the cart, the new customer id is set properly?

I can do it during the ajax call or in the callbask to my js.

Thanks
Abbott
asked Dec 1, 2015 in MultiStore by AbbottF (370 points)
reopened Dec 16, 2015 by AbbottF

Although I can create the anonymous customer and generate a cart. When I try to pass ThisCusomer into session for  redirect to the ShoppingCart, it gets lost.. Is there and ASPDNSF redirect within PageLoad that will handle the session issue?

Here's the PageLoad from the intermediate page.

protected void Page_Load(object sender, System.EventArgs e)
		{
            if (!this.IsPostBack)
            {
                string ReturnURL = CommonLogic.QueryStringCanBeDangerousContent("ReturnUrl");
                AppLogic.CheckForScriptTag(ReturnURL);
                ViewState["ReturnURL"] = ReturnURL;
            }
            // If this is from ananymous pass thru
            if (ThisCustomer.CustomerID == 0)
            {
                using (var _db = new DataAccess())
                {
                    var strCustGuid = Request[Constants.CustomerGuidParam];
                    if (!string.IsNullOrEmpty(strCustGuid))
                    {
                        var efCustomer = _db.GetCustomerByGuid(strCustGuid);
                        if(efCustomer != null)
                        {
                            ThisCustomer = new Customer(efCustomer.CustomerID);
                            ThisCustomer.RequireCustomerRecord();
                            var passThruUrl = efCustomer.PassThruUrl();
                            if (!string.IsNullOrEmpty(passThruUrl))
                            {
                                Response.Redirect(passThruUrl);
                            }
                            else
                            {
                                Response.Redirect(Constants.ShoppingCartUrl);
                            }
                        }
                        else
                        {
                            Response.Redirect(Constants.HomeUrl);
                        }
                    }
                }
            }
        }

 

1 Answer

0 votes

Hi Abbott,

Is the form hosted on the same site (ASPDNSF), or are you redirecting the user from a different website?

If from the same site, have a look at how the native signin logic works. This can be seen on the signin page (you may need to look into the control) or checkoutanon.aspx.cs.

Search for AppLogic.ExecuteSigninLogic(CurrentCustomerID, NewCustomerID); in your solution.

If on an external site, you are going to need a few additional steps, which can get complicated. All possible, but more involved.

Sincerely,
Robert

robert@govedia.com
GoVedia LLC
Enterprise AspDotNetStorefront Development Partner
Web Design, Platform Enhancements & Managed Services

answered Dec 8, 2015 by Robert (3,440 points)
Thanks. It is all one site. It's a good thing for me to use in the future. For a quick fix, since I redirect to the Shopping Cart from the ajax return in javascript, I made the anonomous customerId a parameter and picked it up in my shopping cart load.

Abbott
Robert,

I tried AppLogic.ExecuteSigninLogic(CurrentCustomerID, NewCustomerID), but it only transfers information from current customer to new customer (since currentid = 0, it really does nothing). I need an AppLogic function that will set my new customer into the session customer.

Any other thoughts?

I'll keep looking & trying.

Thanks
Abbott

It seems that Customer.MakeAnonCustomerRecord creates a new record and "sometimes" sets the session.

In case that doesn't happen,  I pushed the Requires request to ShoppingCart.aspx.cs using...

// If this is from annon allocation - use annon customer
if (ThisCustomer.CustomerID == 0)
{
                var strCustId = Request[Constants.SACustomerIdParam];
                if ( !string.IsNullOrEmpty(strCustId))
                {
                    var customerId = 0;
                    if (Int32.TryParse(strCustId, out customerId))
                    {
                        ThisCustomer = new Customer(customerId);
                        ThisCustomer.RequireCustomerRecord();
                    }
                }
}

Thanks again for your help.

Abbott

Abbott,

Yes, ExecuteSigninLogic is only part of the solution. Just pointint you in the section of code I was referring to... also have a look at FormsAuthentication.SetAuthCookie which will initiate the user's session.

Seems like you have the bulk of it figured out.

Sincerely,
Robert
...