1

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.

Community
  • 1
  • 1
DevT
  • 4,843
  • 16
  • 59
  • 92
  • You have two ways, the one is as you goin now, connect your user with their cookie and the final payment., and the other is to send variables to paypal, and reads this variables to connect the user with the payment. If you go with the session, that is connected with the cookie, then is better to use SQL server to save the sessions and not InProc. With sessions on sql you not loose them. – Aristos Feb 20 '14 at 11:31
  • Not that this would cause the problem but a session timeout of 3600 seems a little high? You do know it's in minutes? – Damon Feb 20 '14 at 11:43
  • Do you have one machine on live server, or multiple with load balancing? Try to store session in DB. – Anton Levshunov Feb 27 '14 at 06:31

1 Answers1

1

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

Community
  • 1
  • 1
Shashank Chaturvedi
  • 2,756
  • 19
  • 29
  • even after i disable browser cashe problem is still there. – DevT Feb 25 '14 at 06:28
  • I would suggest you to carry out a test. Do the complete process (that takes you to pay pal), on returning the page is expected to have lost the session. Now clear the browser cache (using developer tools) and then refresh the page. If you session is detected that means the code you added is not successfully removing the cache. Please let me know your findings. – Shashank Chaturvedi Feb 26 '14 at 11:45
  • Do you mean remove session cookie using firebug? – DevT Feb 26 '14 at 12:03
  • No just remove cache. Are you experiencing the same issue in any other browser also other than Firefox? – Shashank Chaturvedi Feb 26 '14 at 12:05
  • Its not just about the browser cache, I would like you to try disabling cache on your page so that it does not cache on server. – Shashank Chaturvedi Feb 26 '14 at 12:14
  • The issue looks more related to server cache since it gets fixed after few attempts of you refreshing the page. Since the server cache is maintained for short time this may happen. – Shashank Chaturvedi Feb 26 '14 at 12:15
  • in chrome it works fine and in IE even after press ctrl+f5 it won't work – DevT Feb 26 '14 at 12:53
  • Did you try disabling the cache on the page (refer the link I shared). – Shashank Chaturvedi Feb 26 '14 at 12:58
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/48478/discussion-between-shashank-chaturvedi-and-devt) – Shashank Chaturvedi Feb 26 '14 at 12:59
  • It seems this is problem with IIS 6. I deployed this in IIS 7 environment and it worked. – DevT Mar 03 '14 at 12:29
  • good you were able to resolve it. Add your solution as answer so it can help anyone with similar issue. – Shashank Chaturvedi Mar 03 '14 at 13:34