Welcome to WebmasterWorld Guest from 54.167.29.208

Forum Moderators: martinibuster

Error: Response must contain the AMP-Access-Control-Allow-Source

     
12:18 pm on Dec 5, 2017 (gmt 0)

New User

joined:Dec 5, 2017
posts:1
votes: 0


Error: Response must contain the AMP-Access-Control-Allow-Source-Origin header

Response must contain the AMP-Access-Control-Allow-Source-Origin header
Form submission failed: Error: Response must contain the AMP-Access-Control-Allow-Source-Origin header​​​

my from

<form id="aa" name="aa" method="post" target="_top" action-xhr="/gonder.asp" enctype="multipart/form-data">
<div class="ampstart-input inline-block relative m0 p0 mb3">
<input class="block border-none p0 m0" type="text" name="adSoyad" placeholder="Ad Soyad" required>
<input class="block border-none p0 m0 telefonKontrol" type="tel" name="telefon" maxlength="10" placeholder="5XX1112233" pattern="[1-9]{1}[0-9]{9}" required>
</div>
<input value="GÖNDER" class="ampstart-btn caps user-valid valid" type="submit">
<div submit-success>
<template type="amp-mustache">
<p>Bilgileriniz bize ula&#351;t&#305;. Size en k&#305;sa sürede geri dönü&#351; yap&#305;lacakt&#305;r.</p>
</template>
</div>
</form>


this c# code

public virtual ActionResult AmpRedirect(string redirectUrl, string __amp_source_origin)
{
if (redirectUrl != string.Empty)
{
HttpContext.Response.AddHeader("AMP-Redirect-To", redirectUrl);
HttpContext.Response.AddHeader("AMP-Access-Control-Allow-Source-Origin", __amp_source_origin);
HttpContext.Response.AddHeader("Access-Control-Expose-Headers", "AMP-Redirect-To, AMP-Access-Control-Allow-Source-Origin");
}

HttpContext.Response.AddHeader("Content-type", "text/json");
return Json(new {Content = ""});
}


I needed a code to work with classic asp
2:37 pm on Dec 5, 2017 (gmt 0)

Senior Member

WebmasterWorld Senior Member Top Contributors Of The Month

joined:Apr 1, 2016
posts:1577
votes: 423


The key 'AMP-Access-Control-Allow-Source-Origin' must have a value of a string representing your source domain eg: 'https://www.example.com'

I'm not certain of details, as I dealt with this issue a few weeks ago but if I recall correctly (I may be wrong about this) __amp_source_origin is not always returned as query string. It depends on what AMP element is sending the CORS request. So it is possible that in your case __amp_source_origin is null and thus throws the error. To be sure that it is correct I assign the hard coded string of my domain instead of depending on __amp_source_origin. This assumes that you will be receiving requests only from a single domain.