C# Asp.net贝宝返回Url要求

C# Asp.net贝宝返回Url要求,c#,asp.net,paypal,C#,Asp.net,Paypal,我正在使用asp.net进行测试程序 //string Server_URL = "https://www.paypal.com/ph/cgi-bin/webscr?"; string Server_URL = ConfigurationManager.AppSettings["URL"].ToString(); //Assigning Cmd Path as Statically to Parameter string

我正在使用asp.net进行测试程序

//string Server_URL = "https://www.paypal.com/ph/cgi-bin/webscr?";
            string Server_URL = ConfigurationManager.AppSettings["URL"].ToString();

            //Assigning Cmd Path as Statically to Parameter
            string cmd = "_xclick";

            //Assigning business Id as Statically to Parameter
            string business = ConfigurationManager.AppSettings["BusinessName"].ToString();

            //Assigning item name as Statically to Parameter
            string item_name = lblProductCode.Text;

            //Passing Amount as Statically to parameter 
            double amount = Convert.ToDouble(_lblPrice.Text);
            Session["Amount"] = amount;

            //Passing Currency as Statically to parameter
            string currency_code = "PHP";

            string redirect = "";

            //Pass your Server_Url,cmd,business,item_name,amount,currency_code variable.        
            redirect += Server_URL;
            redirect += "cmd=" + cmd;
            redirect += "&business=" + business;
            redirect += "&first_name=" + Session["id"].ToString();
            redirect += "&item_name=" + item_name;
            redirect += "&amount=" + amount;
            redirect += "&quantity=1";
            redirect += "&currency_code=" + currency_code;

            redirect += "&return=http://localhost:49457/Fun/Success.aspx";
            redirect += "&cancel_return=" + ConfigurationManager.AppSettings["FailedURL"].ToString();

            Session["Redirect"] = redirect;

            Response.Redirect(redirect);
现在在网站支付偏好 我在代码中的返回中设置了相同的返回URL。 它说“我们无法验证您输入的URL。请检查您的输入并重试。”


是否可以在返回url中插入本地主机url???

据我所知,本地主机url是不可能的。 试试这个:向hosts文件添加一个规则,并将localhost映射到另一个名称,比如“mysite.com”。然后提供带有新名称的URL和您的路径作为PayPal的返回URL。贝宝应该正确地称呼它

用记事本打开windows/system32/drivers/etc/hosts(以管理员身份运行) 添加行:
localhost contoso.example.org

现在,您的返回url将如下所示: 您应该能够在浏览器中打开(它将指向localhost)


然后,在对PayPal API的调用中包含此返回url,并将其放在“支付首选项”页面的字段中

我以前是这样做的,它在本地服务器测试中对我很有效:

protected void imgBtnBuyNow_Clicked(object sender, EventArgs e)
{
    string redirecturl = "";

    //Mention URL to redirect content to paypal site
    redirecturl += "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_xclick&business=" + ConfigurationManager.AppSettings["paypalemail"].ToString();

    //First name i assign static based on login details assign this value
    redirecturl += "&first_name=ehsan";

    //City i assign static based on login user detail you change this value
    redirecturl += "&city=rawalpindi";

    //State i assign static based on login user detail you change this value
    redirecturl += "&state=punjab";

    //Product Name
    redirecturl += "&item_name=" + packageName.Value.ToString();

    //Product Amount
    redirecturl += "&amount=" + tdPrice.InnerHtml;
    //Business contact id
    //redirecturl += "&business=nravindranmca@gmail.com";

    //Shipping charges if any
    redirecturl += "&shipping=5";

    //Handling charges if any
    redirecturl += "&handling=5";

    //Tax amount if any
    redirecturl += "&tax=5";

    //Add quatity i added one only statically 
    redirecturl += "&quantity=1";

    //Currency code 
    redirecturl += "&currency=USD";

    redirecturl += "&invoice=" + packageID.Value.ToString();

    redirecturl += "&custom=" + Session["userid"].ToString() + "," + packageID.Value.ToString() + "," + Session["purchaseType"].ToString();


    //Success return page url
    redirecturl += "&return=" + ConfigurationManager.AppSettings["SuccessURL"].ToString();

    //Failed return page url
    redirecturl += "&cancel_return=" + ConfigurationManager.AppSettings["FailedURL"].ToString();

    Response.Redirect(redirecturl);
}
以下是web.config中的设置:

<add key="token" value="Jlt89XcvKKNRyLICXJCaWBlYoXxPify22EQlz3ZaColy51HdwJz05rILtd4" />
<add key="paypalemail" value="biznes_1357901741_biz@yahoo.com" />
<add key="PayPalSubmitUrl" value="https://www.sandbox.paypal.com/cgi-bin/webscr" />
<add key="FailedURL" value="http://localhost:4076/OpenLearningSolutions/Failed.aspx" />
<add key="SuccessURL" value="http://localhost:4076/OpenLearningSolutions/Success.aspx" />

在paypal sandbox Web payment reference中有一个返回url站点,如果您在那里输入您的本地开发服务器url,则该站点将永远无法工作。您不能这样做。这是一件基本的事情,您必须熟悉,而且在逻辑上是不可能的,它将如何识别您的本地url。您可以将返回url设置为发送给paypal的web请求中的参数,如下所示:

redirecturl += "&return=" + ConfigurationManager.AppSettings["SuccessURL"].ToString();

//Failed return page url
redirecturl += "&cancel_return=" + ConfigurationManager.AppSettings["FailedURL"].ToString();

没有必要在那里设置返回url,因为我们在web请求中发送它

我设置了此url”“有url错误,我使用与本地主机相同的方法来测试我的站点您的错误是什么意思?可能是url无效您不需要在那里输入返回url,因为您正在发送的web请求中设置它,很明显在那个地方你不能进入localhostHi你能详细说明一下吗。我是新加入paypal集成w/asp.net的。谢谢。我只需要这个:tx-交易ID st-付款状态金额-付款金额cc-货币代码在paypal将重定向到Success.aspx页面上的Success.aspx页面后,您可以从请求对象中提取它。您可以从Success.aspx页面的Load of Success.aspx页面获取该值