Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Updated 6-Dec-18 4:26am

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 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);

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;
    }
}
 
Share this answer
 
v2
Comments
Member 13142345 10-Dec-18 1:56am    
Thanks for the solution wevper. i tried to post the values as byte array after encoding. This works fine and they are encoded but after redirecting to response page in the central project the browser says 404 NOT FOUND Error. the page is available on the project but the same error
wevper 10-Dec-18 20:18pm    
Double check the response page is alive online.
wevper 10-Dec-18 20:21pm    
I assume that you are not typing this: "http://www.centralprojet.com/PaymentRequest.aspx" as www.centralproject.com is an example that has to be replaced by your actual domain.
Member 13142345 11-Dec-18 1:43am    
yes the response page is alive. when i did not use the encoded query string then the page is loading. but when i included the encoded query string then the error appears as 404 not found.
wevper 11-Dec-18 21:55pm    
Try put a breakpoint or log the activity step by step to find out which page (or resources) that is actually "not found" (404). It could be something else out of our discussion scope.
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.
 
Share this answer
 
Comments
Member 13142345 10-Dec-18 1:53am    
Yes. I did that using Javascript previously for POSTING the values.
But there is a KEY value i am receving from the paymentgateway, based on that keyvalue i have to dynamically change the URL. but in the action method in aspx page need to write only one address in the URL. so can you help me to navigate to the different URL's based on key the value from the backend.
Thanks in advance

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900