ASP.NET 4.0、C#、Web フォーム、およびマスター ページを使用しています。
Authorize.Net のサイレント投稿機能を実装しようとしていて、いくつかのテスト ページを作成しました。
別のページ (Silent) に投稿するボタンが付いたテスト ページ (Silent_Test) があります。問題は、Silent ページがロードされた場合 (つまり、Silent_Test ユーザーのボタンをクリックして Silent にリダイレクトされ、ページがロードされた場合)、Silent ページが POST を介してのみ情報をキャプチャすることです。情報は Page Load イベントにあるので理にかなっていますが、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();
}
}
}