Application_Errorでは、ScriptManagerに実際にアクセスして、現在のリクエストが非同期ポストバックかどうかを判断できます。グローバルオブジェクトHttpContext.Current.Handlerは、現在処理中のページを指します。このページには、現在の要求が非同期であるかどうかを示すScriptManagerオブジェクトが含まれています。
次の文は、簡潔にScriptManagerオブジェクトにアクセスし、この情報を取得する方法を示しています。
もちろん
ScriptManager.GetCurrent(CType(HttpContext.Current.Handler, Page)).IsInAsyncPostBack
、現在の要求がページのためではない場合、その文は失敗します、あるいは全くのScriptManagerが存在しない場合現在のページに、ので、ここであなたが決意を作るためのGlobal.asax内で使用できる関数のより強固なペアです:
Private Function GetCurrentScriptManager() As ScriptManager
'Attempts to get the script manager for the current page, if there is one
'Return nothing if the current request is not for a page
If Not TypeOf HttpContext.Current.Handler Is Page Then Return Nothing
'Get page
Dim p As Page = CType(HttpContext.Current.Handler, Page)
'Get ScriptManager (if there is one)
Dim sm As ScriptManager = ScriptManager.GetCurrent(p)
'Return the script manager (or nothing)
Return sm
End Function
Private Function IsInAsyncPostback() As Boolean
'Returns true if we are currently in an async postback to a page
'Get current ScriptManager, if there is one
Dim sm As ScriptManager = GetCurrentScriptManager()
'Return false if no ScriptManager
If sm Is Nothing Then Return False
'Otherwise, use value from ScriptManager
Return sm.IsInAsyncPostBack
End Function
ただ、現在の状態を示すブール値を取得するのApplication_Error内からIsInAsyncPostback()を呼び出します。
非同期要求を転送/リダイレクトしようとすると、より多くのエラーが生成され、元のエラーが置き換えられ、難読化されるため、クライアントで一般的なASP.NETエラーが発生します。このような場合には、上記のコードを使用して転送やリダイレクトを防ぐことができます。
このメソッドを使用してScriptManagerオブジェクトにアクセスすることはできますが、何らかの理由でApplication_Error内のAsyncPostBackErrorMessageプロパティを設定しても機能しません。新しい値はクライアントに渡されません。したがって、ページクラスのScriptManagerのOnAsyncPostBackErrorイベントを処理する必要があります。
http://www.codedigest.com/Articles/ASPNETAJAX/115_Error_Handling_in_ASPNet_Ajax_Applications.aspx –
申し訳ありませんが、既にAllowCustomErrorsRedirect = falseを使用しており、AsyncPostBackErrorMessageを提供しています。だから私は記事がどのように関連しているかはわかりません。 OnAsyncPostBackErrorハンドラの使用を含む質問が更新されました。 – BlueFox