我有一个Payment
控制器,它公开了一个名为HttpPost
的{{1}}操作方法。当我的外部支付服务向我发送立即付款通知(IPN)时,此操作将发布,其唯一目的是根据我在IPN中收到的数据更新我的数据。它永远不会返回视图,那么我的action方法应该返回什么?我确定付款服务需要HTTP 200或其他东西以响应IPN帖子。
答案 0 :(得分:1)
您可以返回empty result:
return new EmptyResult();
答案 1 :(得分:1)
return new HttpStatusCodeBoundedResult(200, "IPN accepted");
return new HttpStatusCodeBoundedResult(400, "Bad IPN request");
public class HttpStatusCodeBoundedResult : HttpStatusCodeResult
{
/// <summary>
/// Initializes a new instance of <see cref="HttpStatusCodeBoundedResult"/>.
/// </summary>
/// <param name="statusCode">The status code.</param>
public HttpStatusCodeBoundedResult(int statusCode) : base(statusCode)
{
}
/// <summary>
/// Initializes a new instance of <see cref="HttpStatusCodeBoundedResult"/>.
/// </summary>
/// <param name="statusCode">The status code.</param>
/// <param name="statusDescription">The status description. Will be
/// truncated to 512 characters and have \r\n characters stripped.</param>
public HttpStatusCodeBoundedResult(int statusCode, string statusDescription)
: base(statusCode, ApplyHttpResponseBoundary(statusDescription, 512))
{
}
private static string ApplyHttpResponseBoundary(string input, int length)
{
input = input.Replace("\r", string.Empty).Replace("\n", string.Empty);
return input.Length <= length ? input : input.Substring(0, length);
}
}
答案 2 :(得分:0)
您可以让它返回void
。