2011-07-21 80 views
1

我有一個Payment控制器,它暴露了HttpPost操作方法Notify。當我的外部付款服務向我發送即時付款通知(IPN)時,此行爲將被髮送到我的外部付款通知,它的唯一目的是根據我在IPN中收到的數據更新我的數據。它從不返回視圖,那麼我的操作方法應該返回什麼?我確定付款服務需要一個HTTP 200或其他東西來響應IPN帖子。從外部網站調用的POST操作返回什麼?

回答

1

你可以返回一個empty result

return new EmptyResult(); 
0

你可以只是使它返回void

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

謝謝,很高興知道有一個HttpStatusCodeResult,並從它派生的好想法。 – ProfK

+1

我絕對不建議使用原始的HttpStatusCodeResult,在生產系統崩潰以獲取描述中超過512個字符的消息或者其中存在換行符後。我像 -_-。我不明白爲什麼MS寧願讓你的網站崩潰在這裏比自己修復它。 –