3

如何从以下 URL 获取特定值我只需要获取 3 个值

http://earnprofitclickint.com/UserWorking/Successfull.aspx?lr_paidto=U9925362&lr_amnt=2.00&lr_currency=LRUSD&lr_store=http%3A%2F%2Fwww.earnprofitclickint.com&lr_merchant_ref=&lr_paidby=U3563444&lr_fee_amnt=0.00&lr_transfer=143636187&lr_timestamp=2013-12-05+18%3A31%3A33&ctl00%24contentplaceholder1%24amount=&ctl00%24contentplaceholder1%24id=70&ctl00%24contentplaceholder1%24txtamount=+2&ctl00%24contentplaceholder1%24username=networker&lr_encrypted=04E20ADA982A2AF9C1C64DB3C1601BA596373E22D7B4D21813A51C43DC0198CD&lr_encrypted2=59C8269D431F915360F3B8179EC95181D8C458AB91D72AF3DFC1DC0DFDAC4F64

我想从 Liberty Reserve 网站返回的上述 URL 中获取 3 个值,并希望使用 LINQ TO SQL 将这三个值插入数据库

我需要得到以下值

r_amnt=2.00 ID=70 username=networker

我已经在页面加载中编写了代码,以便在响应到来时获取上述值并重定向到我的成功页面:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        ID.Value = Request.QueryString["id"].ToString();
        UserName.Value = Request.QueryString["username"].ToString();
        Amount.Value = Request.QueryString["lr_amnt"].ToString();

        SaveLocalHistory();
        Divmessage.Visible = true;
    }
}

public void SaveLocalHistory()
{
    MLMDataContext db = new MLMDataContext();

    UsersInvestement pd = new UsersInvestement();
    pd.Amount = Convert.ToDouble(Amount.Value);
    pd.UserId = Convert.ToInt32(ID.Value);
    pd.UserName = UserName.Value;
    pd.Description = "This amount has been received From LR";
    pd.IncomeTypeId = 4;
    pd.CreatedDate = DateTime.Now.Date;
    db.UsersInvestements.InsertOnSubmit(pd);
    db.SubmitChanges();
}

这是 URL 中的手动更改:

http://earnprofitclickint.com/UserWorking/Successfull.aspx?lr_paidto=U9925362&lr_amnt=2.00&lr_currency=LRUSD&lr_store=http%3A%2F%2Fwww.earnprofitclickint.com&lr_merchant_ref=&lr_paidby=U3563444&lr_fee_amnt=0.00&lr_transfer=143636187&lr_timestamp=2013-12-05+ 18%3A31%3A33&ctl00%24contentplaceholder1&amount=&ctl00%24contentplaceholder1&id=70&ctl00%24contentplaceholder1%24txtamount=+2&ctl00%24contentplaceholder1&username=networker&lr_encrypted=04E20ADA982A2AF9C1C64DB3C1601BA596373E22D7B4D21813A51C43DC0198CD&lr_encrypted2=59C8269D431F915360F3B8179EC95181D8C458AB91D72AF3DFC1DC0DFDAC4F64


如果我手动更改它,那么它可以工作。任何想法?

4

2 回答 2

1

您的参数名称不是usernameand id,它们是ctl00$contentplaceholder1$usernameforusernamectl00$contentplaceholder1$idforid

由于%24当 URLDecode 给出时$,您也需要进行相应的替换。

尝试这个:

ID.Value = Request.QueryString["ctl00$contentplaceholder1$id"].ToString();
UserName.Value = Request.QueryString["ctl00$contentplaceholder1$username"].ToString();
Amount.Value = Request.QueryString["r_amnt"].ToString();

它应该可以工作。否则让我知道!:)

于 2013-05-14T06:31:18.367 回答
0

我相当确定查询字符串值区分大小写,这意味着此代码

ID.Value = Request.QueryString["ID"].ToString();
UserName.Value = Request.QueryString["UserName"].ToString();
Amount.Value = Request.QueryString["lr_amnt"].ToString();

应该是这种形式

ID.Value = Request.QueryString["id"].ToString();
UserName.Value = Request.QueryString["username"].ToString();
Amount.Value = Request.QueryString["r_amnt"].ToString();

如果你想取出“r_amnt=2.00 id=70 username=networker”


顺便说一句,请注意您永远不会处理您的数据库上下文。这可能很危险,因为您的连接可能在很长一段时间内都不会关闭,我建议您这样做:

using( MLMDataContext db = new MLMDataContext() )
{
 UsersInvestement pd = new UsersInvestement();
 pd.Amount = Convert.ToDouble(Amount.Value);
 pd.UserId = Convert.ToInt32(ID.Value);
 pd.UserName = UserName.Value;
 pd.Description = "This amount has been received From LR";
 pd.IncomeTypeId = 4;
 pd.CreatedDate = DateTime.Now.Date;
 db.UsersInvestements.InsertOnSubmit(pd);
 db.SubmitChanges();
}

using 语句确保Dispose在 DataContext(继承自 IDisposable)上调用它,并在操作完成后正确关闭连接。

于 2013-05-12T19:46:56.090 回答