views:

405

answers:

1

Hi all!

I have the following scenario to implement:

I have an ASP.NET Web site. On a click of a button in my site the user is redirected to a 3rd party site. When the user does some actions in this 3rd party site, the site starts sending http post requests to my site with a special message every 1 minute.

Now, the problem is that I should handle and process these requests, but I do not know how to do it. Please note that the requests that are sent from the 3rd party site DO NOT open my site by the http post requests. These requests are some kind of background requests, i.e. they do not open a page directly, so they should be handled using another approach.

I have the solution in Java. It is called Servlet. By the help of the servlet I can do the thing that I want in Java. However, I need the same functionality in ASP.NET? Does anybody have a solution for this?

Thanks a lot!

P.S. Just for your reference, here is the Java code for the servlet:

package payment;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import beans.action.PaymentBean;

public class EPayRequestCatcher extends javax.servlet.http.HttpServlet
  implements javax.servlet.Servlet {
 static final long serialVersionUID = 1L;

 public EPayRequestCatcher() {
  super();
 }

 protected void doGet(HttpServletRequest request,
   HttpServletResponse response) throws ServletException, IOException {

  doPost(request, response);
 }

 protected void doPost(HttpServletRequest request,
   HttpServletResponse response) throws ServletException, IOException {

  String encoded = request.getParameter("encoded");
  PaymentUtil util = new PaymentUtil();
  if (encoded != null) {
  String decoded = util.getDecodedB64Data(encoded);
  int invStart = decoded.indexOf("=") + 1;
  int invEnd = decoded.indexOf(":", invStart);
  String invoice = decoded.substring(invStart, invEnd);
  System.out.println(""+invoice);
  String checksum = request.getParameter("checksum");
  PaymentBean bean = new PaymentBean();
  String responseStatus = bean.getEpayRequest(encoded, checksum);
   if (!responseStatus.equals("")) {
    String responseData = "INVOICE=" + invoice + ":STATUS=" + responseStatus + "\n";
    System.out.println(responseData);
    response.getWriter().append(responseData);

   }
  } else {
    return;
  }
 }
}

enter code here enter code here

A: 

TheVisitor,

if I understood well, an external website will POST some data to your ASP.NET website; you'll (probably) define a page to receive that post and don't know how to handle it, right?

Well, you can try something like:

protected void Page_Load(object sender, EventArgs e)
{
    string encoded = Request["encoded"];
    string checksum = Request["checksum"];

    // do stuff

    Response.Write("some response");
}

This could be enough, depending on you requirements.

HTH

Rubens Farias
Hi, thank you for your response.My problem is not in the implementation of a page. My problem is in handling and processing the request. I.e. the 3rd party side sends the request and the purpose of the request that they send IS NOT to open a page. They send it somehow in background. Now let's say I want to open a page on receiving the request. How can I get the request and say 'hey, I just got an external request, let's open a page (or let's modify an existing page in a session, or anything else).
TheVisitor
@Visitor, so how other side will POST that data to you? They need a URI to send data...
Rubens Farias
@Rubens, I pass my URL as a parameter when I do the POST request to the 3rd party site, so they know it when they should start bombing me with their POSTs
TheVisitor