cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to read Relay Response POST Data in ASP.NET

I am using SIM, trying to get relay_response to work on a test account with an ASP.NET 2.0 application.  It is displaying the response URL page fine, but there is no data displayed... it's as if there was no form data posted to it at all, the same as if you just typed in the URL.

 

However, when I use https://developer.authorize.net/tools/paramdump/ as the response url I can see the posted data, so I know the problem is probably not with Authorize.net.  However, when I post to my response page from a test page, it does recognize and display the posted data, so I know the page is handling the posted data correctly.  

This is the test page that DOES work... the response page does display the posted data:

 

 

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
<form id="form1" runat="server"  method='post' action="http://localhost/www.faea.org/FAEAWeb/TransSuccess.aspx">
<input type='hidden' runat="server" name='x_response_code' id='x_response_code' value="1" />
<input type='hidden' runat="server" name='x_response_reason_text' id='x_response_reason_text' value='Test response reason text' />
<input type='hidden' runat="server" name='x_description' id='x_description' value="Test Description" />
<input type='submit' runat="server" id='buttonLabel' />
</div>
</form>
</body>
</html>

 

But for some reason, whenever Authorize.net posts to my response page after a transaction, the page comes up but with none of the POST data.  

 

I have disabled viewStateMAC in the Page directive.  I'm not behind a firewall other than the Windows 7 firewall.  I'm running IIS 7 and the application is using ASP.NET 2.0.   I'm not getting any error messages anywhere, it's just displaying my response page with all the data fields empty. 

 

Here is my ASP.Net script that is handling the relay response page:

 

 

 

  Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Response.Expires = 0  '--I've tried with and without the Response.Expires

            Dim s_x_response_code As String = ""
            If Not String.IsNullOrEmpty(Request.Form("x_response_code")) Then
                s_x_response_code = Request.Form("x_response_code")
            End If

            Dim n_x_response_reason_code As Integer = 0
            If Not String.IsNullOrEmpty(Request.Form("x_response_reason_code")) Then
                n_x_response_reason_code = CInt(Request.Form("x_response_reason_code"))
            End If

            Dim s_x_response_reason_text As String = ""
            If Not String.IsNullOrEmpty(Request.Form("x_response_reason_text")) Then
                s_x_response_reason_text = Request.Form("x_response_reason_text")
            End If

            Dim s_x_auth_code As String = ""
            If Not String.IsNullOrEmpty(Request.Form("x_auth_code")) Then
                s_x_auth_code = Request.Form("x_auth_code")
            End If

            Dim s_x_invoice_num As String = ""
            If Not String.IsNullOrEmpty(Request.Form("x_invoice_num")) Then
                s_x_invoice_num = Request.Form("x_invoice_num")
            End If

            Dim s_x_description As String = ""
            If Not String.IsNullOrEmpty(Request.Form("x_description")) Then
                s_x_description = Request.Form("x_description")
            End If

            Dim s_x_amount As String = ""
            If Not String.IsNullOrEmpty(Request.Form("x_amount")) Then
                s_x_amount = Request.Form("x_amount")
            End If

            If s_x_response_code = "1" Then
                UpdateTransaction(s_x_invoice_num)
                lblDescription.Text = "TRANSACTION APPROVED!! <BR /> A receipt has been sent to the e-mail address you provided on the previous screen.<br /><br />" & _
                    s_x_description & "<br />Total Amount: " & s_x_amount & "<br />Approval Code: " & s_x_auth_code
            Else
                lblDescription.Text = "YOUR CARD HAS BEEN DECLINED!!!!<BR />" & s_x_response_code & "<br />" & s_x_response_reason_text & "<br /><br />"
               
            End If
        End Sub

 

 

In searching these forums, I found that someone was told by Authorize.net support that you can't use ASP.NET with Relay Response, you have to use classic ASP (which I really don't want to do), but others have gotten it to work using EnableViewStateMAC="false" so I do have hope that this is possible and there is just something else that I haven't thought about yet.

 

Any help would be greatly appreciated!!!!

 

 

joshbula99
Contributor
46 REPLIES 46

I've tried both "false" and "UseCookies" and neither work.  It's an old app that's been converted from .net 1.1 (and maybe from Classic asp before that), but when I created a new application from scratch to test it,  I'm just getting "Invalid Viewstate" errors no matter what I do.

On the new app did you set the EnableViewStateMAC="false"

I did, yes.  I think it has to do with the fact that ASP.NET 4.0 expects viewstate that is encoded a certain way, and the viewstate field coming from Authorize.net is incompatible so it thinks it's invalid.  I need a way to just ignore ViewState all together.  I tried EnableViewState="false" and ViewStateMode="Disabled" but still got the error.

We are still on ASP.net 3.5 sp1, so maybe that why I'm not seeing your error.

I don't think authorize.net is posting a viewstate field but I will test it out tomorrow.

Have you look at the event viewer? It might have more detail on the error.

Did the test html post work?

When I set the relay_response url to the Authorize.net data validation url, it did show a "___VIEWSTATE" field.  Since the actual application is .net 2.0, I"m not going to worry about the viewstate problem in the new app, but rather focus on the cookie redirect thing... I think that's the real problem: it's losing the post data when it redirects.

Ok.... I'm getting somewhere!!!! I put this in the web.config:

 <anonymousIdentification enabled="false" />

 

And that has prevented the cookie detection redirect, so it is now reading the POST data.  Yay! :)  

 

However, now I'm getting the ViewStateException that I was getting with my new blank test app:

System.Web.HttpException: The state informaiton is invalid for this page and might be corrupted.  --> System.Web.UI.ViewStateException: Invalid ViewState.

 

The only way I can access the POST data is to put code in the Page_Error event to e-mail it to me or do something with it.  But that's obviously not a solution because it's displaying that generic error page to the user.

 

So... back to solving the ViewState problem...  

Here is an example of Relay Response in .NET. If you continue to have problems you can try it to see if it helps.

 

 

<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
    // Normally this would go in a codebehind file, but for the example I made it all one file.
    string x_response_code = Request["x_response_code"];
    string x_response_reason_code = Request["x_response_reason_code"];
    string reason_text = "";
    string x_auth_code = "";
    string x_trans_id = "";
    string x_prepaid_balance_on_card = "";
    string x_amount = "";
    bool successfulTransaction = ("1" == x_response_code || "4" == x_response_code);
    if (successfulTransaction)
    {
        reason_text = "Thank you for your order";
        x_auth_code = Request["x_auth_code"];
        x_trans_id = Request["x_trans_id"];
        x_prepaid_balance_on_card = Request["x_prepaid_balance_on_card"];
        x_amount = Request["x_amount"];
    }
    else
    {
        reason_text = Request["x_response_reason_text"];
        if (string.IsNullOrEmpty(reason_text))
        {
            reason_text = "This transaction failed.";
        }
    }
%>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Relay Response Example</title>
    <style type="text/css">
        .MainContent { width: 600px; margin: 10px auto; }
        .CompanyLogo { background-color: #99D9EA; text-align: center; padding: 8px; }
        .SuccessMessage { font-size: larger; }
        .DeclineMessage { font-size: larger; color: Red; }
        .DefaultSpacing { height: 20px; }
    </style>
</head>
<body>
    <div class="MainContent">
        <div class="CompanyLogo">
            Your company logo here
        </div>
        <div class="DefaultSpacing">
        </div>
        <div class="? successfulTransaction <%="SuccessMessage" : "DeclineMessage" %>">
            <%= Server.HtmlEncode(reason_text) %>
        </div>
        <div class="DefaultSpacing">
        </div>
        <table>
            <tr><td>Amount:</td><td>$<%= Server.HtmlEncode(x_amount) %></td></tr>
            <tr><td>Transaction ID:</td><td><%= Server.HtmlEncode(x_trans_id) %></td></tr>
            <tr><td>Authorization Code:</td><td><%= Server.HtmlEncode(x_auth_code) %></td></tr>
            <% if (!string.IsNullOrEmpty(x_prepaid_balance_on_card)) { %>
                <tr><td>Remaining balance on card: </td><td>$<%= Server.HtmlEncode(x_prepaid_balance_on_card) %></td></tr>
            <% } %>
        </table>
        <div class="DefaultSpacing">
        </div>
        <div>
            You may also include:
            <ul>
                <li>x_card_type and x_account_number, or eCheck information</li>
                <li>Billing address information: x_first_name, x_last_name, x_company, x_address, x_city, x_state, x_zip, x_country</li>
                <li>x_phone and x_email</li>
                <li>x_invoice_num and x_description</li>
                <li>Shipping address information: x_ship_to_first_name, x_ship_to_last_name, etc.</li>
                <li>x_tax, x_freight</li>
            </ul>
        </div>
        <div class="DefaultSpacing">
        </div>
        <div class="CompanyLogo">
            Your company logo here
        </div>
    </div>
</body>
</html>

 

 

Thanks,

 

Elaine

Elaine
Trusted Contributor
Trusted Contributor

joshbula99,

 Not sure if you find a solution but I did some "bing"ing and the closest thing I found that might fix your problem is

 

onsubmit="var v=document.getElementById('__VIEWSTATE');v.parentNode.removeChild(v);"

Add that to the <form ... action="https://test.authorize.net/gateway/transact.dll" onsubmit=".....">

 

Thank you for your help.... I finally got it working.  I disabled ViewStateMAC temporarily for the entire site and it worked.  That made me realize that I had fogotten to put the EnbableViewStateMac="false" in the page that requests the payment form.  It was only in the response page.  I can't believe it was something so small... I am positive that I had it in both pages, but I must have removed it while trouble-shooting the cookie detection redirect thing and forgot to put it back.  Thanks again .... I wouldn't have been able to figure this out without your help.

Great to hear you got it to work. And thanks for posting the solution.