我正在测试支付提供商 (SagePay),作为流程的一部分,他们的服务器会发布到我的站点并期望得到响应。我无法使用 MVC 让它工作。
我设置了一个经典的 asp 测试响应页面并将其添加到我的 MVC 应用程序中:
<%
Response.Buffer = True
response.Clear()
response.contenttype="text/plain"
response.write "Status=OK" & vbCRLF
response.write "RedirectURL=http://www.redirectsomewhere.co.uk" & vbCRLF
response.End()
%>
这工作很好。
但是,当我尝试对 MVC 执行相同操作时,它不起作用:
Controller :
[HttpPost]
public ActionResult TestCallback()
{
return View();
}
看法:
@{
Response.Buffer = true;
Response.Clear();
Response.ContentType = "text/plain";
Response.Write("Status=OK" + System.Environment.NewLine);
Response.Write("RedirectURL=http://www.redirectsomewhere.co.uk" + System.Environment.NewLine);
Response.End();
}
该错误消息是来自支付提供商的一般错误,因此没有真正的帮助,但我已将错误范围缩小到页面呈现的点。
我可以很好地浏览两个页面(为此我需要从 MVC Controller 方法中删除 HttpPost 属性),并且两个页面都显示相同的数据。
这是支付提供商发布到的 MVC url:
http://myipaddress/CA_UAT/Token/TestCallback
这是可以正常工作的经典 asp URL:
http://myipaddress/CA_UAT/Token/TestCallback.asp
我为 asp 页面创建了一个“ token ”目录,以便 url 匹配以进行测试。
我究竟做错了什么?
更新
为了回应 Hari 的评论,我安装了一个名为“Header Spy”的 Firefox 插件,它为我提供了以下信息:
Response HTTP/1.1 200 OK
Source: Response
HttpHeader:Server
Request:User-Agent Cookie
Response:Response Date Set-Cookie
两个页面显示相同的信息。
最佳答案
您无需返回操作结果即可将纯文本发送回屏幕。完成此操作的最简单方法是返回一个字符串值。将 Controller 中的代码替换为以下代码。
[HttpPost]
public string TestCallback()
{
string result = "Status=OK";
result += System.Environment.NewLine;
result += "RedirectURL=http://www.redirectsomewhere.co.uk";
result += System.Environment.NewLine;
return result;
}
这将不会返回您在字符串中的其他响应。通过使用 ActionResult 和 View,您可能会从主视图返回标记。
关于asp.net-mvc-3 - 从 3rd 方站点发布到我的 ASP.NET MVC 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10246571/