RNG隐藏字段参数

时间:2013-02-28 21:59:40

标签: c# asp.net

我有一份注册表,我正在接收用户输入并将信息传递给付款网站。支付网站有几个隐藏字段,因此它可以将每个用户区分为唯一,而不是依赖于用户提供的唯一名称。这就是“unique_id”字段,我想要一个随机数作为参数。我如何才能使这项工作如此,每当用户点击附加此代码的按钮时,它就会执行RNG并将该号码传递给外部支付网站?

...

    protected void submitButton_Click(object sender, EventArgs e)
    {
Random randnum = new Random();
int num = randnum.Next();
        {
            NameValueCollection PostFields = new NameValueCollection();
            PostFields.Add("LMID", "345573");
            PostFields.Add("unique_id", RANDOM NUMBER HEEDS TO GO HERE);
            PostFields.Add("sTotal", "150.00");
            PostFields.Add("webTitle", "Conference");
            PostFields.Add("Trans_Desc", "Conference Registration");
            PostFields.Add("contact_info", "Contact admin");
            PostFields.Add("BILL_CUSTOMER_FIRSTNAME", labelFirstName.Text);
            PostFields.Add("BILL_CUSTOMER_LASTNAME", labelLastName.Text);
            PostFields.Add("BILL_ADDRESS1", labelAddress.Text);
            PostFields.Add("BILL_CITY", labelCity.Text);
            PostFields.Add("BILL_STATE", labelState.Text);
            PostFields.Add("BILL_ZIP", labelZip.Text);
            PostFields.Add("BILL_CUSTOMER_PHONE", labelTelephone.Text);
            PostFields.Add("BILL_CUSTOMER_EMAIL", labelEmail.Text);
            RedirectAndPOST(this.Page, "payment website url", PostFields);
        }

...

1 个答案:

答案 0 :(得分:1)

这对我来说很好用:

    Random random = new Random(); int num = random.Next();

    NameValueCollection PostFields = new NameValueCollection();
    PostFields.Add("LMID", "093204"); 
    PostFields.Add("unique_id", num.ToString());