cancel
Showing results for 
Search instead for 
Did you mean: 

Silent Post not Posting: Page Load Event Issue?

I'm using ASP.NET 4.0, C#, Web Forms, and Master Pages.

 

I've looked all over and can't figure out why this isn't working. I have a test page (Silent_Test) with button that posts to another page (Silent). The problem seems to be that the Silent page only captures the information through POST if the Silent page loads. It makes sense since the information is in the Page Load event, but I understand that Authorize.Net's Silent Post will not load the page so how can I capture their POST information if the page is never loaded? Is my understanding off or am I going about this the wrong way?...Can anyone provide tips or sample code?

 

Silent_Test.ASPX

<%@ Page Title="Silent Test" Language="C#" MasterPageFile="~/MasterPages/Site.master" AutoEventWireup="true"
  CodeFile="Silent_Test.aspx.cs" Inherits="_Silent_Test" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">
<form action="https://www.test.com/silent.aspx" method="post">
    <input type="hidden" name="x_response_code" value="9"/>
    <input type="hidden" name="x_cust_id" value="99999999-9999-9999-9999-999999999999"/>
    <input type="submit"/>
</form>
</asp:Content>

 

Silent_Test.ASPX.CS

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Silent_Test : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
      
    }
}

 

 

Silent.ASPX

<%@ Page Title="Silent" Language="C#" MasterPageFile="~/MasterPages/Site.master"
  AutoEventWireup="true" CodeFile="Silent.aspx.cs" Inherits="_Silent" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">
  <div>
    <%--    There is no need to put anything in the .ASPX file since Authorize.net's
    server does not care about the response from the POST call.--%>
    <p>
      You have reached this page in error. Please verify you have the correct web page
      address.
    </p>
  </div>
</asp:Content>

 

 

Silent.ASPX.CS

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;

  public partial class _Silent : BasePage
  {
    protected void Page_Load(object sender, EventArgs e)
    {
      string connectionString =
      ConfigurationManager.ConnectionStrings["ASPNETDBConnectionString1"].ConnectionString;
      string insertSql = "INSERT INTO Silent(x_cust_id, x_response_code) VALUES(@cust_id,@response_code)";
      using (SqlConnection myConnection = new SqlConnection(connectionString))
      {
        myConnection.Open();
        SqlCommand myCommand = new SqlCommand(insertSql, myConnection);
        myCommand.Parameters.AddWithValue("@cust_id", this.Request.Form["x_cust_id"]);
        myCommand.Parameters.AddWithValue("@response_code", this.Request.Form["x_response_code"]);
        myCommand.ExecuteNonQuery();
        myConnection.Close();
      }
    }
  }

 

 

john1379
Member
15 REPLIES 15

I'm not sure what your problem is exactly? I assume your post works ok, and you're only theorizing that Authorize.net will work differently? Have you actually tested it by sending through a transaction to find out what happens?

TJPride
Expert

I've testing through Authorize.Net and when the User encounters the hosted Receipt page the information is not written to the database.

 

However, when the user encounters the hosted Receipt page with a "Default Receipt URL" POST button  directed at my "Silent.aspx" page the data is written to my database. So I'm not sure where the problem is, page load? post?

If you are using https, maybe somehow authorize.net is rejecting the ssl cert.

Also, since it is simlar to relay response, other thread had people said to set Page EnableViewStateMac="false"

In your control panel, you have to specify all the relay response URL's you use on your site. Have you specified this one? If not, it obviously isn't going to work.

I couldn't get the Silent Post to work as I imagined it should; User submits payment information, User goes to Authorize.Net hosted receipt, Auth sends a silent post to my website that is then written to database, and finally User clicks a link to redirect back to my website.

 

So I decided to use a workaround; User submits payment information, Relay Response URL page writes information to my database on page load and ends with a redirect back to my website where I can pull the data written to my database and show to user if needed. So in the end all works, thanks for the pointers.

 

* I tried the viewstatemac = false method button it didn't work for me and after reading MSDN's security note I decided it's best to leave that feature enabled, better safe than sorry especially since I'm a beginner!

 

MSDN

john1379
Member

I'm having the exact same issue.  I created a sample page as suggested with a basic form using all the possible fields and a simple submit button.  When i use it it fires fine with no issues but i get nothing when a transaction takes place.  Any ideas?

Just to clarify, is it the Silent Post that is not working? Or Relay Response?


-------------------------------------------------------------------------------------------------------------------------------------------
John Conde :: Certified Authorize.Net Developer (Brainyminds) :: Official Authorize.Net Blogger

NEW! Handling Authorize.Net's Webhooks with PHP

Integrate Every Authorize.Net JSON API with One PHP Class (Sample code included)

Tutorials for integrating Authorize.Net with PHP: AIM, ARB, CIM, Silent Post
All About Authorize.Net's Silent Post

First check that your silent post URL is correctly configured, as in copy and paste from the Authorize.net control panel and see if the page loads in your browser. If it does, that leaves two possibilities. First, Authorize.net could be having problems connecting to it, in which case it's probably something to do with slow DNS. You can perhaps fix that problem most of the way by setting the refresh on your DNS to something quite long, like two weeks. Second, Authorize.net could be connecting but your page isn't interpreting the data properly. Have you tried just doing a var dump of POST to a text file to see if data is coming through at all? Test it by submitting a small form to the page and make sure the data is being logged.

@Stymiee:  My issue is specific to the silent post.

 

Maybe i'm going about this the wrong way but if you try and just load the page you get a null ref exception.

 

Line 13:     protected void Page_Load(object sender, EventArgs e)

Line 14:     {

Line 15:         if (!Request.Form["x_invoice_num"].ToString().Equals(""))

Line 16:         LoadRecordInDB();

Line 17:     }

 

This works fine when i access the page from my test form as it's passing data.  I will modify my code to just dump the vars to a log.  If you have any other suggestions on how to implment this i'm all ears!  :)