我正在使用 ASP.NET 4.0、C#、Web 窗体和母版页。
我正在尝试实现 Authorize.Net 的 Silent Post 功能并创建了几个测试页面
我有一个测试页面(Silent_Test),带有发布到另一个页面(Silent)的按钮。问题似乎是静默页面仅在静默页面加载时才通过 POST 捕获信息(即,单击 Silent_Test 用户上的按钮重定向到静默和页面加载)。这是有道理的,因为信息在页面加载事件中,但我知道 Authorize.Net 的 Silent Post 不会加载页面,所以如果页面从未加载,我如何捕获他们的 POST 信息?我的理解是错误的还是我的方法不对?...任何人都可以提供提示或示例代码来捕获/处理 Authorize.Net 在静默帖子中发送的信息吗?
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 - 代码未修改 -
静音.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>
沉默的.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();
}
}
}