簡體   English   中英

Async Await MVC Action返回Task而不是ActionResult

[英]Async Await MVC Action returning Task instead of ActionResult

我的行動如下:

public async Task<ActionResult> Pair(string id)
    {
        try
        {
            DocuSignAPIManager docuSignAPIManager = new DocuSignAPIManager();

            DocuSignEsignatureAuthContainer authContainer = await docuSignAPIManager.Pair(User.Identity.Name, id).ConfigureAwait(false);

            DocuSignManager.Instance.Pair(User.Identity.Name, authContainer);
        }
        catch(Exception e)
        {
            ErrorManager.Instance.LogError(e);
        }

        return new HttpStatusCodeResult(200);
    }

當調用該操作時,將執行所有邏輯,但是我收到以下內容而不是HTTP Status 200代碼:

System.Threading.Tasks.Task`1[System.Web.Mvc.ActionResult]

為了測試我只是使用以下URL從Web瀏覽器調用操作:

http://localhost:20551/CharteredSurveyor/Pair/password

我真的不明白問題是什么 - 有人可以幫忙嗎?

ELMAH中的ErrorHandlingControllerFactory返回一個自定義動作調用程序,用於確保將其HandleErrorWithElmahAttribute應用於控制器。 它從不提供異步動作調用程序,因此它不理解async / await。

兩個解決方法;

  1. 嘗試升級到最新的ELMAH - 它可能有針對async / await的修復。
  2. 刪除對ControllerBuilder.Current.SetControllerFactory(new ErrorHandlingControllerFactory())的調用,並使用GlobalFilters.Filters.Add(new HandleErrorWithElmahAttribute());簡單地將HandleErrorWithElmahAttribute添加到全局過濾器GlobalFilters.Filters.Add(new HandleErrorWithElmahAttribute());

干杯,迪恩

這對我有用,

改變

public class authController : Controller

public class authController : AsyncController

我創建了包含異步操作的控制器類,該操作使該錯誤繼承自AsyncController類而不是默認的Controller類

我在這里找到答案

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM