這裏有兩個問題,用戶點擊提交按鈕多次,用戶在另一個時間點填寫表單。
對於第二個我可以看到兩個相當簡單的解決方案會推薦一個會話cookie,只需cookie用戶機器,不要讓他們再次看到表單,或要求一個信息,如電子郵件地址,然後檢查如果之前使用過數據庫,如果這樣忽略新的表單細節。
對於多表單提交,您可以使用此代碼,這將禁用按鈕onclick。
//
// Disable button with no secondary JavaScript function call.
//
public static void DisableButtonOnClick(Button ButtonControl)
{
DisableButtonOnClick(ButtonControl, string.Empty);
}
// Disable button with a JavaScript function call.
//
public static void DisableButtonOnClick(Button ButtonControl, string ClientFunction)
{
var sb = new StringBuilder(128);
// If the page has ASP.NET validators on it, this code ensures the
// page validates before continuing.
sb.Append("if (typeof(Page_ClientValidate) == 'function') { ");
sb.Append("if (! Page_ClientValidate()) { return false; } } ");
// Disable this button.
sb.Append("this.disabled = true;");
// If a secondary JavaScript function has been provided, and if it can be found,
// call it. Note the name of the JavaScript function to call should be passed without
// parens.
if (!String.IsNullOrEmpty(ClientFunction))
{
sb.AppendFormat("if (typeof({0}) == 'function') {{ {0}() }};", ClientFunction);
}
// GetPostBackEventReference() obtains a reference to a client-side script function
// that causes the server to post back to the page (ie this causes the server-side part
// of the "click" to be performed).
sb.Append(ButtonControl.Page.GetPostBackEventReference(ButtonControl) + ";");
// Add the JavaScript created a code to be executed when the button is clicked.
ButtonControl.Attributes.Add("onclick", sb.ToString());
}
也許餅乾是最好的方法;當用戶在代理服務器後訪問應用程序時,IP阻塞可能會導致一些誤報 –