そこで、フォームの二重送信の問題に対処する方法として、PRG と呼ばれるこのメソッドを調べました。ただし、ユーザーに表示される概要ページ/成功メッセージの降下実装をまだ見つけていません。私が考えることができる唯一の方法は、セッション変数を保存することですが、複数の更新で保持したくありません。メッセージ/概要を一度表示すれば完了です。さらに、ユーザーが以前に送信されたページに戻れないことが理想的です。
これが私のPRGコードです:
Protected Sub InsertRequest() Handles wizard.FinishButtonClick
Using connection As New SqlConnection(connectionStr)
Dim insertQuery As New SqlCommand("spInsertRequest", connection)
insertQuery.CommandType = CommandType.StoredProcedure
'1 - SETUP SQL PARAMETERS (omitted for brevity)
'2 - POST (inserts record into DB)
Try
connection.Open()
insertQuery.ExecuteNonQuery()
connection.Close()
Catch ex As Exception
Logger.WriteToErrorLog(Me, ex.Source, ex.Message, ex.StackTrace)
End Try
'3 - REDIRECT (to the same page and...)
Try
Dim urlRedirect As String = If(IsNothing(Request.Url), "", IO.Path.GetFileName(Request.Url.AbsolutePath)) 'Gets the filename of the current page.
If Not String.IsNullOrEmpty(urlRedirect) Then
Session.Add("referrerPage", urlRedirect) 'Used for identifying when the page is being redirected back to itself.
PageExt.AddParam(urlRedirect, "id", recID.ToString)
Response.Redirect(urlRedirect)
End If
Catch ex As Exception
Logger.WriteToErrorLog(Me, ex.Source, ex.Message, ex.StackTrace)
End Try
End Sub
'4 - GET (Display 'Success' message/summary here)
問題は、このメッセージを送信の結果として直接リダイレクトに表示する方法です。または、更新に関係なく、最も簡単で最も意味のあるメッセージを表示するだけです。ありがとう ;)