title: How to redirect from my asp.net website to payment form of authorised.net Payment Gateway
body: <p>I have created an asp.net webform. One button is there on the form when I click on the button I need to redirect overpayment form authorized payment gateway with the amount and need to capture the response with the transaction id but I don't understand how to redirect over the gateway.</p>
  
  <p>I read their developer document and got to know that need to pass token with URL and to generate token it needs customer profile id. so I need to understand how to generate proper token.</p>
  
  <p>I am using this code to generate token:</p>
  
  <pre><code>//build a path to IframeCommunicator from the calling page
  string communicatorPath = String.Format("{0}://{1}:{2}", callingPage.Scheme, callingPage.Host, callingPage.Port);
  string[] segments = callingPage.Segments;
  //replace the very last entry with contentx/IframeCommunicator.html
  segments[segments.GetUpperBound(0)] = "/contentx/IframeCommunicator.html";
  foreach(string s in segments)
  communicatorPath += s;
  
  string requestXML = String.Format("&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;" +
   "&lt;getHostedProfilePageRequest xmlns=\"AnetApi/xml/v1/schema/AnetApiSchema.xsd\"&gt;" +
   "&lt;merchantAuthentication&gt;" +
   "&lt;name&gt;{0}&lt;/name&gt;" +
   "&lt;transactionKey&gt;{1}&lt;/transactionKey&gt;" +
   "&lt;/merchantAuthentication&gt;" +
   "&lt;customerProfileId&gt;{2}&lt;/customerProfileId&gt;" +
   "&lt;hostedProfileSettings&gt;" +
   "&lt;setting&gt;" +
   "&lt;settingName&gt;hostedProfilePageBorderVisible&lt;/settingName&gt;" +
   "&lt;settingValue&gt;false&lt;/settingValue&gt;" +
   "&lt;/setting&gt;" +
   "&lt;setting&gt;" +
   "&lt;settingName&gt;hostedProfileIFrameCommunicatorUrl&lt;/settingName&gt;" +
   "&lt;settingValue&gt;{3}&lt;/settingValue&gt;" +
   "&lt;/setting&gt;" +
   "&lt;/hostedProfileSettings&gt;" +
   "&lt;/getHostedProfilePageRequest&gt;",
   "API_LOGIN_ID", "TRANSACTION_KEY", CustomerProfileId, communicatorPath);
  
  string XMLURL = "https://apitest.authorize.net/xml/v1/request.api";
  System.Net.HttpWebRequest req = (System.Net.HttpWebRequest) System.Net.HttpWebRequest.Create(XMLURL);
  req.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore);
  req.KeepAlive = false;
  req.Timeout = 30000; //30 seconds
  req.Method = "POST";
  byte[] byte1 = null;
  System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
  byte1 = encoding.GetBytes(requestXML);
  req.ContentType = "text/xml";
  req.ContentLength = byte1.Length;
  System.IO.Stream reqStream = req.GetRequestStream();
  reqStream.Write(byte1, 0, byte1.Length);
  reqStream.Close();
  
  System.Net.WebResponse resp = req.GetResponse();
  System.IO.Stream read = resp.GetResponseStream();
  System.IO.StreamReader io = new System.IO.StreamReader(read, new System.Text.ASCIIEncoding());
  string data = io.ReadToEnd();
  resp.Close();
  
  //parse out value
  XmlDocument doc = new XmlDocument();
  doc.LoadXml(data);
  XmlNodeList m_AccessToken = doc.GetElementsByTagName("token");
  return m_AccessToken[0].InnerText;
  </code></pre>
  
  <p>and to generate customer profile id I am using the following code:</p>
  
  <pre><code> // set whether to use the sandbox environment, or production enviornment
   ApiOperationBase &lt; ANetApiRequest, ANetApiResponse &gt; .RunEnvironment = AuthorizeNet.Environment.SANDBOX;
  
   // define the merchant information (authentication / transaction id)
   ApiOperationBase &lt; ANetApiRequest, ANetApiResponse &gt; .MerchantAuthentication = new merchantAuthenticationType() {
  
    name = ApiLoginID,
     ItemElementName = ItemChoiceType.transactionKey,
     Item = ApiTransactionKey,
   };
  
   //standard api call to retrieve response
   paymentType cc = new paymentType {
    Item = "Credit Card"
   };
   paymentType echeck = new paymentType {
    Item = "Credit Card"
   };
  
   List &lt; customerPaymentProfileType &gt; paymentProfileList = new List &lt; customerPaymentProfileType &gt; ();
   customerPaymentProfileType ccPaymentProfile = new customerPaymentProfileType();
   ccPaymentProfile.payment = cc;
  
   customerPaymentProfileType echeckPaymentProfile = new customerPaymentProfileType();
   echeckPaymentProfile.payment = echeck;
  
   paymentProfileList.Add(ccPaymentProfile);
   paymentProfileList.Add(echeckPaymentProfile);
  
   List &lt; customerAddressType &gt; addressInfoList = new List &lt; customerAddressType &gt; ();
   customerAddressType homeAddress = new customerAddressType();
   homeAddress.address = "10900 NE 8th St";
   homeAddress.city = "Seattle";
   homeAddress.zip = "98006";
  
  
   customerAddressType officeAddress = new customerAddressType();
   officeAddress.address = "1200 148th AVE NE";
   officeAddress.city = "NorthBend";
   officeAddress.zip = "92101";
  
   addressInfoList.Add(homeAddress);
   addressInfoList.Add(officeAddress);
  
  
   customerProfileType customerProfile = new customerProfileType();
   // customerProfile.merchantCustomerId = "22";
   customerProfile.email = emailId;
   customerProfile.paymentProfiles = paymentProfileList.ToArray();
   //customerProfile.shipToList = addressInfoList.ToArray();
  
   var request = new createCustomerProfileRequest {
    profile = customerProfile, validationMode = validationModeEnum.none
   };
  
   //instantiate the controller that will call the service
   var controller = new createCustomerProfileController(request);
   controller.Execute();
   //get the response from the service (errors contained if any)
   createCustomerProfileResponse response = controller.GetApiResponse();
  
   // validate response 
   if (response != null) {
    if (response.messages.resultCode == messageTypeEnum.Ok) {
     if (response.messages.message != null) {
  
      Console.WriteLine("Customer Profile ID: " + response.customerProfileId);
      Console.WriteLine("Payment Profile ID: " + response.customerPaymentProfileIdList[0]);
      Console.WriteLine("Shipping Profile ID: " + response.customerShippingAddressIdList[0]);
     }
    } else {
     Console.WriteLine("Customer Profile Creation Failed.");
     Console.WriteLine("Error Code: " + response.messages.message[0].code);
     Console.WriteLine("Error message: " + response.messages.message[0].text);
    }
   } else {
    if (controller.GetErrorResponse().messages.message.Length &gt; 0) {
     Console.WriteLine("Customer Profile Creation Failed.");
     Console.WriteLine("Error Code: " + response.messages.message[0].code);
     Console.WriteLine("Error message: " + response.messages.message[0].text);
    } else {
     Console.WriteLine("Null Response.");
    }
   }
  
   return response;
  </code></pre>
  
  <p>but code is not working.</p>