Integration and Testing

Authorize.Net API questions and help with your payment integration.

Reply
Contributor
Posts: 10
Registered: ‎02-22-2011

Re: Unable to read Relay Response POST Data in ASP.NET

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.

Expert
Posts: 4,525
Registered: ‎03-08-2010

Re: Unable to read Relay Response POST Data in ASP.NET

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

Contributor
Posts: 10
Registered: ‎02-22-2011

Re: Unable to read Relay Response POST Data in ASP.NET

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.

Expert
Posts: 4,525
Registered: ‎03-08-2010

Re: Unable to read Relay Response POST Data in ASP.NET

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?

Contributor
Posts: 10
Registered: ‎02-22-2011

Re: Unable to read Relay Response POST Data in ASP.NET

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.

Contributor
Posts: 10
Registered: ‎02-22-2011

Re: Unable to read Relay Response POST Data in ASP.NET

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...  

Trusted Contributor
Posts: 451
Registered: ‎08-21-2009

Re: Unable to read Relay Response POST Data in ASP.NET

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

Expert
Posts: 4,525
Registered: ‎03-08-2010

Re: Unable to read Relay Response POST Data in ASP.NET

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=".....">

 

Contributor
Posts: 10
Registered: ‎02-22-2011

Re: Unable to read Relay Response POST Data in ASP.NET

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.

Expert
Posts: 4,525
Registered: ‎03-08-2010

Re: Unable to read Relay Response POST Data in ASP.NET

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