【问题标题】:sand box redirection destroys sessions沙盒重定向会破坏会话
【发布时间】:2012-12-15 01:46:19
【问题描述】:

为什么当我从我的本地主机将用户重定向到 PAYPAL 的沙箱 (https://www.sandbox.paypal.com) 然后在返回到 .aspx 页面 (successful.aspx) 后会丢失会话,

例如SESSION [“tempUser”],它适用于everypage但不适用于Successful.aspx页面,它返回null,我正在处理这个错误2周,但没有进展, 我尝试了不同的浏览器,甚至不同的系统,稍微更改了代码,但没有任何帮助,已经 1 个月以上,在几个表单上发布了几篇帖子后,没有任何帮助,即使 cookie 有同样的问题,返回时为空,我之前的帖子。

重定向页面代码:

<body>
    <form id="form1" runat="server">
<div>
 <h4> Congrats <b> <%# Session["tempSubAdminName"]%>  </b>, Your basic informaton has been submitted , For full activation you need to pay via paypal. Please click the PayPal icon given below. </h4>
</div>
<div>
 <asp:HyperLink ID="homeBtnImage" runat="server" ImageUrl="~/btnPayPal.gif"
      NavigateUrl= "https://www.sandbox.paypal.com/us/cgi-bin/webscr?cmd=_xclick&business=smile2_1355775057_biz@yahoo.com&item_name=MemberShip&amount=20&currency=USD&return=http://127.0.0.1:57135/Online%20Recruitment%20System-Final/paymentSuccessful.aspx?emailAdmin='1234' &cancel_return=https://www.google.com/" >PayPal</asp:HyperLink>
</div>
<h6>Or if you don't have paypal account, click <asp:HyperLink ID="paypalSite" runat="server"
    NavigateUrl="https://www.sandbox.paypal.com/" >here</asp:HyperLink> </h6>
</form>

如果成功返回这个年龄

</head>
 <body>
   <form id="form1" runat="server">
   <div>
     <h5> Dear <%# Session["tempSubAdmin"] %>, You have successfully registered ,   Please wait for the approval by admin. </h5>
</div>
</form>

【问题讨论】:

  • Session["tempSubAdmin"] 是否应该与 Session["tempSubAdminName"] 相同?
  • 底线是我尝试时会话丢失了
  • 你能分享你的代码吗?
  • 如何重定向以及如何返回?
  • 使用这行我做重定向 sandbox.paypal.com/us/cgi-bin/…' &cancel_return=google.com" >贝宝

标签: asp.net paypal sandbox


【解决方案1】:

我认为您正在本地机器上进行测试。

在重定向之前检查 cookie ASP.NET_SessionId 的值。

然后在successful.aspx调用后查看值。

如果 cookie 丢失:Paypal 无法对您的 cookie 做任何事情。只能在同一个域(本地主机)上更改。

我会在没有贝宝的情况下对此进行测试:只需一个简单的页面即可重定向到您的successful.aspx。如果 cookie 丢失,您可能配置了非常短的 Session Timeout 或运行了一些删除 cookie 的代码(检查 global.asax)

【讨论】:

    【解决方案2】:

    我正在解释我实施的方式。可能因人而异。

    1. 首先您必须在developer paypal api 上创建一个帐户。帐户。
    2. 然后创建两个测试帐户,一个用于客户,另一个用于企业(商家)。
    3. web.config 文件中声明这些值。

       <appSettings>    
          <!--these keys are for Paypal-->
          <add key="paypalURL" value="https://www.sandbox.paypal.com" />
          <add key="paypalAccount" value="arshad_Mer_biz@gmail.com" />
          <add key="websiteUrl" value="http://www.yourstie.com" />
        </appSettings>
      
    4. 现在你必须相应地设置paypal html变量,详情Paypal variables

    5. button_click 事件中编写以下代码

      string redirectUrl = ConfigurationManager.AppSettings["paypalURL"]+"/cgi-bin/webscr?cmd=_xclick";
      string sellersEmail = "&business=";
      string buyersEmail = "&email=";
      string productName = "&item_name=";
      string amount = "&amount=";
      string shippingOption = "&no_shipping=";
      string noteOpton = "&no_note=";
      string returnUrl = "&return=";
      string cancelUrl = "&cancel_return=";
      string rmOption = "&rm=";
      string notifyUrl = "&notify_url=";
      string custom = "&custom=";
      
      // Merchant account
      sellersEmail += ConfigurationManager.AppSettings["paypalAccount"];
      
      //calling a method that will return current user email id.
      buyersEmail += GeneralClass.GetUserEmail();
      
      //optional value if you want to carry
      custom += GeneralClass.GetUseriD();
      
      productName += lblProdeutName.Text;
      amount +=lblAmount.Text ;
      
      shippingOption += "1";                      //1 means no shipping option;
      noteOpton += "1";                           //1 means no note option;
      rmOption += "1";                            
      
      returnUrl +=ConfigurationManager.AppSettings["websiteUrl"]+"/PaypalThankYou.aspx";
      cancelUrl +=ConfigurationManager.AppSettings["websiteUrl"] + "/PaypalCancel.aspx";
      notifyUrl += ConfigurationManager.AppSettings["websiteUrl"] + "/PaypalNotifyUrl.aspx";
      
      redirectUrl += sellersEmail + buyersEmail + productName + amount + shippingOption +    noteOpton + returnUrl + cancelUrl + notifyUrl + rmOption + custom;
      Response.Redirect(redirectUrl);
      

    取消页面:- 如果用户从 paypal 取消交易。它也适用于本地主机。
    感谢页面:付款后,paypal会跳转到页面。
    通知网址:有时称为 IPN(即时付款通知)。这是您将从贝宝获得价值的地方。它仅适用于托管页面。 它在本地主机上不起作用

    Notifyurl 页面的代码
    添加这些namespaces:

     using System.Net;
     using System.IO;
     using System.Text;
     using System.Collections.Specialized;
    

    page_load:

      protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
             //Post back to either sandbox or live
            string strURL =ConfigurationManager.AppSettings["paypalURL"]+ "/cgi-bin/webscr";
    
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strURL);
    
            //Set values for the request back
            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            byte[] param = Request.BinaryRead(HttpContext.Current.Request.ContentLength);
            string strRequest =Encoding.ASCII.GetString(param);
            string strResponse_copy = strRequest;  //Save a copy of the initial info sent by PayPal
            strRequest += "&cmd=_notify-validate";
            req.ContentLength = strRequest.Length;
    
            //for proxy
            //WebProxy proxy = new WebProxy(new Uri("http://url:port#"));
            //req.Proxy = proxy;
            //Send the request to PayPal and get the response
    
            StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
            streamOut.Write(strRequest);
            streamOut.Close();
            StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
            string strResponse = streamIn.ReadToEnd();
            streamIn.Close();
    
            if (strResponse == "VERIFIED")
            {
                //check the payment_status is Completed
                //check that txn_id has not been previously processed
                //check that receiver_email is your Primary PayPal email
                //check that payment_amount/payment_currency are correct
                //process payment
                // pull the values passed on the initial message from PayPal
    
                NameValueCollection these_argies = HttpUtility.ParseQueryString(strResponse_copy);
    
                string pay_stat = these_argies["payment_status"];
    
                //.
                //.  more args as needed look at the list from paypal IPN doc
                //.
    
    
                if (pay_stat.Equals("Completed"))
                {
                //inserting the database
                    int intUserID;
                    int.TryParse(these_argies["custom"],out intUserID);
                    objUserEntity.UserID=intUserID;
                    objPapalPayment.strTransactionID = these_argies["txn_id"];
                    objPapalPayment.dblPaymentAmount = Convert.ToDouble(these_argies["payment_gross"]);
                    objPapalPayment.strBuyerMail = these_argies["payer_email"];
                    objPapalPayment.dtmDateAppliedOn = DateTime.Now;
                    objPapalPayment.blnIsGlobalAdvertisement = true;
                    objSubscription.blnIsPaid = false;
                    objSubscription.blnSubscriptionWithHeld = true;
                    objUserFunction.AddPaypalPayment(objUserEntity, objPapalPayment, objSubscription, enmSubscriptionType.Global);                         
                }
    
    
                // more checks needed here specially your account number and related stuff
            }
            else if (strResponse == "INVALID")
            {
                //log for manual investigation
            }
            else
            {
                //log response/ipn data for manual investigation
            }
            }
        }
    

    那你将如何在 localhost 上调试呢? 使用rm value =2;并将相同的代码粘贴到感谢页面的 page_load 事件中。它会起作用的。

    更多详情: http://www.codeproject.com/Articles/42894/Introduction-to-PayPal-for-C-ASP-NET-developers
    Paypal variables and its usage
    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-31
      • 2019-04-17
      • 2015-12-09
      • 2015-07-02
      相关资源
      最近更新 更多