如何将值从一个项目的aspx页面发布到另一个项目的aspx页面 [英] How to POST the values from one project aspx page to another project aspx page

查看:68
本文介绍了如何将值从一个项目的aspx页面发布到另一个项目的aspx页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在整合支付网关页面和一个项目,我正在收集客户信息以预订酒店房间和所有细节,然后将这个项目的值发布到另一个项目aspx页面,这是一个中心项目。从该中心项目我将值发布到支付网关页面。



主项目 - > ReservationDetails.aspx

将值发布到

中央项目 - > PaymentRequest.aspx

然后将相同的值发布到支付网关页面。



从paymentgateway页面返回后



中央项目 - > Reposnse.aspx

并且需要将相同的值发布到

主项目 - > Reposnse.aspx



重新点击来自paymentgateway页面后,我使用了以下代码



我尝试了什么:



会话[MerchantCode] = Request.From [MerchnatCode]

通过这种方式我已经收集了会话值并重定向到另一个项目页面使用

Response.Redirect(Rep.aspx,false)

但我发现会话值是点击Rep.aspx页面后空了。



所以我收集了代码



我有不同酒店的不同商家代码。

因此根据给定的商家代码,我需要将值发布到操作方法网址。



那么,如何在aspx页面中使用action方法将值发布到不同的URL

或者无论如何都要在C#代码中实现这一点。



无论如何都要从支持的代码动态更改FORM POST方法。

I am integrating a payment gateway page with one project where i am collecting the customer information for booking the hotel room and all the details and then posting the values from this project to another project aspx page which is a central project. from that central project i am posting the values to payment gateway page.

Main Project --> ReservationDetails.aspx
Posting the values to
Central Project-->PaymentRequest.aspx
then posting the same values to payment gateway page.

After returning from the paymentgateway page

Central Project --> Reposnse.aspx
and needs to post the same values to
Main Project --> Reposnse.aspx

After retunring the from paymentgateway page i have used the below code

What I have tried:

Session["MerchantCode"] = Request.From[MerchnatCode]
by this way i have collected the values to sessions and redirecting to another project page by using
Response.Redirect("Rep.aspx",false)
But i found that the session values are empty after hitting the Rep.aspx page.

so i have collected the code to

I have different merchant codes for different hotels.
so based on the given merchant code i need to POST the values to the action method URL.

so, how could i POST the values to Different URL by using action method in aspx page
or is there anyway to achieve this in the C# code.

Is there anyway to dynamically change the FORM POST method from backed code.

推荐答案

有很多方法可以将数据传递到另一个页面。



如果你的两个项目都是C#,那么你可以使用DataTable / ByteArray作为实现此目的的可能解决方案之一。



在您的主项目中,您可以执行以下操作:

There are many ways to pass data to another page.

If both of your projects are C#, then you can use DataTable/ByteArray as one of the possible solution to do this.

At your main project, you can do something like this:
DataTable dt = new DataTable();
dt.Columns.Add("transaction_id");
dt.Columns.Add("user_id");
dt.Columns.Add("amount", typeof(decimal));

dt.Rows.Add("AA0001", "1234", 450.90m);

byte[] ba = ConvertToBytes(dt);

string data = Convert.ToBase64String(ba);
string dataEncoded = Server.UrlEncode(data);

Response.Redirect("http://www.centralprojet.com/PaymentRequest.aspx?q=" + dataEncoded);



And然后,在您的中心项目中,在Page_Load()方法中,您可以执行以下操作:


And then, at your central project, at the Page_Load() method, you can do something like this:

string dataEncoded = Request.QueryString["q"];
string data = Server.UrlDecode(dataEncoded);

byte[] ba = Convert.FromBase64String(data);

DataTable dt = ConvertToObject<DataTable>(ba);

string transaction_id = dt.Rows[0]["transaction_id"] + "";
string user_id = dt.Rows[0]["user_id"] + "";
decimal amount = (decimal)dt.Rows[0]["amount"];



如果您希望在后端完成该过程而不重定向到另一个页面,然后你静默地执行此操作而不通知用户/浏览器。


If you wish the process to be done in backend without redirecting to another page, then you do this silently without notifying the user/browser.

DataTable dt = new DataTable();
dt.Columns.Add("transaction_id");
dt.Columns.Add("user_id");
dt.Columns.Add("amount", typeof(decimal));

dt.Rows.Add("AA0001", "1234", 450.90m);

byte[] ba = ConvertToBytes(dt);
WebClient wc = new WebClient();
byte[] baResult = wc.UploadData("http://www.centralproject.com/PaymentRequest.aspx", ba);

string result = System.Text.Encoding.UTF8.GetString(baResult);



然后,在您的CentralProject中,您可以静默处理数据并使用后端返回结果:


Then, at your CentralProject, you can silently process the data and return the result using backend too:

byte[] ba = Request.BinaryRead(Request.ContentLength);

DataTable dt = ConvertToObject<DataTable>(ba);

string transaction_id = dt.Rows[0]["transaction_id"] + "";
string user_id = dt.Rows[0]["user_id"] + "";
decimal amount = (decimal)dt.Rows[0]["amount"];

// do something

Response.Write("success");



这是代码块将对象转换为字节数组:


Here is the code block for converting object to byte array:

public static byte[] ConvertToBytes(Object obj)
{
    using (MemoryStream ms = new MemoryStream())
    {
        BinaryFormatter bf = new BinaryFormatter();
        bf.Serialize(ms, obj);
        return ms.ToArray();
    }
}

public static T ConvertToObject<T>(byte[] bytes)
{
    using (MemoryStream memStream = new MemoryStream(bytes))
    {
        BinaryFormatter bf = new BinaryFormatter();
        var obj = (T)bf.Deserialize(memStream);
        return obj;
    }
}


首先,propject只是一种在IDE中对某些文件进行分组的方法,它没有关注终端站点的运行方式。根据您对项目的处理,他们可能能够共享Session,但他们可能不会。如果每个项目都部署到不同的网站,那么他们就无法共享会话。



如果您想要发布到网址,很遗憾,您将不得不这样做它来自javascript。创建一个页面,其中包含具有所需操作URL的表单,并将表单值放在隐藏字段中,然后使用javascript在页面加载时提交表单。它有点笨重,但这是唯一的方法。



一般来说,你不应该在会话中存储这种数据,你应该依赖任何ids \您从支付平台获得的令牌等,以便从像数据库一样持久的某个地方检索您的数据。当用户从支付网关返回时,您无法保证会话仍然存在且可用。
First of all a "propject" is simply a way of grouping certain files in the IDE, it has no bearing on how the end site is going to function. Depending on what you do with your projects they might be able to share Session, they might not. If each project is deployed to a different website then they can't share session.

If you want to POST to a url unfortunately you're going to have to do it from javascript. Create a page that has the form with the required action url, and put the form values in hidden fields, then use javascript to submit the form on page load. It's a bit clunky but it's the only way.

In general you shouldn't store this kind of data in the Session anyway, you should rely on whatever ids\tokens etc you get from the payment platform to retrieve your data from somewhere persistent like a database. You can't guarantee the Session is still going to be there and usable when the user comes back from the payment gateway.


这篇关于如何将值从一个项目的aspx页面发布到另一个项目的aspx页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆