I have an AspNet/AngularJS website (using System.Web.Http version 5.2.6.0), I'm adding card payment integration, with 3DS security. 3DS has this step called "data device gathering" where the PSP endpoint sends you back an url and you have to post it into a hidden iframe on the frontend.
Presumably there's some javascript that gathers the device data, and then redirects the iframe to an url you have provided. It almost doesn't matter what page is behind that url, the important thing is listening for the redirect. It just needs to contain some specific html so you can verify you were redirected to the correct page.
So I just added a static page to my website and provided the url. The redirect attempt resulted in "405 method not allowed" because the PSP's device gathering logic does a POST to the redirect url.
So I'm trying to make an API method that allows POST and returns a html page. This has proved unexpectedly challenging. These are some of the things I've tried from answers here on StackOverflow:
[HttpPost]
[AllowAnonymous]
[Route("methodnotification")]
public NegotiatedContentResult<string> MethodNotification()
{
return base.Content(System.Net.HttpStatusCode.OK,"<div id = \"threeDSMethodData\" name = \"threeDSMethodData\" > PROCESSING...</ div >");
}
This will return the following in PostMan:
"<div id = "threeDSMethodData" name = "threeDSMethodData" > PROCESSING...</ div >"
It may look OK, but it's actually a string of type application/json; charset=utf-8. I tried the POST from FireFox, it returns this:
< string> <div id = "threeDSMethodData" name = "threeDSMethodData" > PROCESSING...</ div > < /string>
Even setting the Accept header to only accept "text/html" will return a "plain text" not html. I've tried different overloads of base.Content, which required me to add a "formatter" (if I also wanted to specify content type), and change the return type of the method to FormattedContentResult. After experimenting with different formatters I gave up because it just keeps giving me JSON or string.
I've also tried the following:
return new System.Web.Mvc.ContentResult
{
Content = "<div id = \"threeDSMethodData\" name = \"threeDSMethodData\" > PROCESSING...</ div >",
ContentType = "text/html"
};
Note the fully qualified name was necessary here because if I add a using statement for System.Web.Mvc, all my annotations start giving me "ambiguous reference" between System.Web.Mvc and System.Web.Http. This approach also returned a JSON file.
How do I return html from a POST in ASPNET?
EDIT: The API project targets .NET Framework 4.6. I wish I knew which version of ASPNET that corresponded to.