DevT
DevT

Reputation: 4933

Session variable get empty after paypal and recieve value after press ctrl+f5

I faced weird situation where my session variable set it to null once after coming back from PayPal.

In my scenario before redirect page to PayPal i assign value to session.

 public string sessionToken
        {
            get
            {
                if (Session["token"] != null)
                {
                    return Session["token"].ToString();
                }
                else
                    return string.Empty;
            }
            set
            {
                Session["token"] = value;
            }
        }

calling paypal:

 bool ret = payPalCaller.ShortcutExpressCheckout(amt, ref token, ref retMsg, ref status);
 if (ret)
    {
          sessionToken = token;
          Response.Redirect(retMsg,false);
     }

after user complete paypal (if user takes some time to complete txn) and return back to sucess page and from there i'm trying to access above session variable, then that value is empty. but if i press ctrl+f5 few times then it get value. what is the problem in here? in my development pc, this is working fine and problem occurs when i hosted in server. (IIS 6)

My web config configuration as follows:

<configuration>
  <location path="RegisterUser.aspx">
    <system.web>
      <authorization>
        <allow users="?" />
      </authorization>
      <httpRuntime executionTimeout="43200" maxRequestLength="104856" />
      <sessionState timeout="3600" mode="InProc" cookieless="false"></sessionState>
      <customErrors mode="ON" />
    </system.web>
  </location>
</configuration>

EDIT:

i have used similar code in Checkout and Payment with PayPal. i found this weird question mentioned in the comment section, but no reply for that question as well.

Upvotes: 1

Views: 1670

Answers (1)

Shashank Chaturvedi
Shashank Chaturvedi

Reputation: 2793

If pressing ctrl+F5 fixes the issue for you then your success page may just be cached. Try disabling cache on your success page, that might just do the trick. You can refer to this link for reference: Disabling browser caching for all browsers from ASP.NET

Upvotes: 1

Related Questions