HttpContext.AllowAsyncDuringSyncStages HttpContext.AllowAsyncDuringSyncStages HttpContext.AllowAsyncDuringSyncStages HttpContext.AllowAsyncDuringSyncStages Property


取得或設定值,表示在 ASP.NET 要求各部分處理期間,是否允許未預期的非同步作業。Gets or sets a value that indicates whether asynchronous operations are allowed during parts of ASP.NET request processing when they are not expected.

 property bool AllowAsyncDuringSyncStages { bool get(); void set(bool value); };
public bool AllowAsyncDuringSyncStages { get; set; }
member this.AllowAsyncDuringSyncStages : bool with get, set
Public Property AllowAsyncDuringSyncStages As Boolean


如果 ASP.NET 在未預期的情況下使用了非同步 API 而擲回例外狀況,則為 false;否則為 truefalse if ASP.NET will throw an exception when the asynchronous API is used at a time when it is not expected; otherwise, true. 預設值為 falseThe default value is false.


如果此旗標未設定為true, 則 ASP.NET 會在偵測到應用程式濫用非同步 API 時擲回例外狀況。If this flag is not set to true, ASP.NET will throw an exception when it detects the application misusing the async API. 如果您嘗試在不預期非同步作業的要求處理管線期間呼叫非同步方法, 或在非同步模組或處理常式信號完成時仍有未完成的非同步工作, 就會發生這種情況。This can occur if you try to call an asynchronous method during a part of the request processing pipeline where asynchronous operations are not expected, or if there is still outstanding asynchronous work when an asynchronous module or handler signals completion. 這種行為的目的是為了讓您在撰寫不符合預期模式的非同步程式碼, 而且可能會有負面副作用的情況下, 及早知道您的安全網路。This behavior is meant as a safety net to let you know early on if you're writing async code that doesn't fit expected patterns and might have negative side effects.