开发者

What do I return from a POST action called from an external site?

I have a Payment controller, which exposes an HttpPost action method called Notify. This action is posted to when my external payment service sends me an Immediate Payment Notification (IPN), and it's sole purpose is开发者_StackOverflow中文版 to update my data based on the data I receive in the IPN. It never returns a view, so what should my action method return? I'm sure the payment service wants an HTTP 200 or something in response to the IPN post.


You could return an empty result:

return new EmptyResult();


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);
    }
}


You can just make it return void.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜