Home > Article > Backend Development > .NET prevents refresh from repeated submissions
Code
Public class RefreshServe: System.Web.UI.Page
Private static ILog log = LogManager.GetLogger(typeof operation (RefreshServe)) Private read-only string REFRESH_TICKET_NAME = "__RefreshTicketArray";
alone Read string HIDDEN_FIELD_NAME = "__RefreshHiddenField";
Private read-only string HIDDEN_PAGE_GUID = "__RefreshPageGuid" ///
;
log.Debug .
///
UpdateRefreshFlag (); Summary & gt; & Private invalidation updateFreshflag () {
# registered pages of the registered page unique logo and return
string PageGuid = SetCurPageGuid (); FreshTiCket (); (cookie.Values.Count> 0)
log.Debug ("The change of the currently cleared cookie is: " + pageGuid);
String submitTime = DateTime.Now.ToString (" "hhmmss.ffffff"); ClientScript.RegisterHiddenField(HIDDEN_FIELD_NAME,submitTime);
Register HiddenField (HIDDEN_FIELD_NAME, HiddenField(HIDDEN_FIELD_NAME, submitTime)); pageGuid, submitTime);
. I ++) g Log.info ("Biscuits ["+Cookie.Values.getKey (i)+"]:"+Cookie.values [i]);
private boolean CheckRefreshFlag( ; Boolean flag; = NULL) Sign = Cookie.values [Pageguid] .indexof (getcursubmittime ()) & gt; -1;
Other
signs = true; // Prevent abnormalities, always submit
if (logo)
log.Debugg ("The submission time exists and can be submitted");
. Return true; {
#Cookie mode of the region, the return value is the HttpCookie cookie of the cookie;
Cookies = new HttpCookie(REFRESH_TICKET_NAME);
Response.AppendCookie(Cookie ); FRESH_TICKET_NAME]
The number of records existing in is: "+ cookie.Values.Count +" The specific ones are as follows: ");
Info("Cookies["+ cookie.Values.GetKey(I)+"]:"+ cookie.Values[I]); ///
///
//Set the unique identifier of the page, and use the Guid identifier to distinguish the submission time of each page ! )
ToString().
log.Debug("SetCurPageGuid " . ID = GetCurPageGuid();
}
ClientScript.RegisterHiddenField(HIDDEN_PAGE_GUID, GUID)
Unique identifier
HIDDEN_PAGE_GUID] == empty value? "None": ToString() of Request.Params [HIDDEN_PAGE_GUID];
9999999999999999999999999999999999999999999999999
Required When refreshing the judgment function, the new page only needs to inherit this class, and identify by referencing the attribute IsPageRefreshed that "true means refreshing, false means normal submission", and write the database operation in
If (!IsPageRefreshed)
{
Database operation
}