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(); } } }
12-09-2011 02:18 PM
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?
12-09-2011 03:34 PM
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?
12-09-2011 04:28 PM
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"
12-09-2011 06:19 PM - edited 12-09-2011 06:24 PM
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.
12-10-2011 05:58 AM
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!
12-10-2011 09:51 AM
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?
01-04-2012 09:44 AM
Just to clarify, is it the Silent Post that is not working? Or Relay Response?
01-04-2012 09:51 AM
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.
01-04-2012 10:27 AM
@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! :)
01-04-2012 11:39 AM - edited 01-04-2012 11:50 AM