标签:
01 function newGuid() { 02 var g = ""; 03 for (var i = 0; i < 32; i++) { 04 g += Math.floor(Math.random() * 0xF).toString(0xF); 05 } 06 return g; 07 } 08 09 //gets a new guid and assigns its value to the hidden field 10 function createPageIdentifier() { 11 var guid = this.newGuid(); 12 document.getElementById(‘__REFRESH_FIELD‘).value = guid; 13 }
01 private static Guid GetPageGuid(Page page) 02 { 03 string str = page.Request.Form["__REFRESH_FIELD"]; 04 return (!string.IsNullOrEmpty(str) ? new Guid(str) : Guid.Empty); 05 } 06 07 public void Init(HttpApplication application) 08 { 09 guids = new Queue(queueSize); 10 11 application.PreRequestHandlerExecute += new EventHandler(RefreshModule.Application_PreRequestHandlerExecute); 12 } 13 14 private static void Page_Init(object sender, EventArgs e) 15 { 16 Page page = sender as Page; 17 if (page != null) 18 { 19 page.ClientScript.RegisterOnSubmitStatement(typeof(RefreshModule), "onsubmit", "createPageIdentifier();"); 20 page.ClientScript.RegisterHiddenField("__REFRESH_FIELD", ""); 21 22 HttpContext.Current.Items["IsRefreshed"] = false; 23 if (page.Request.HttpMethod == "POST") 24 { 25 Guid pageGuid = GetPageGuid(page); 26 bool flag = guids.Contains(pageGuid); 27 HttpContext.Current.Items["IsRefreshed"] = flag; 28 if (!flag && (pageGuid != Guid.Empty)) 29 { 30 guids.Enqueue(pageGuid); 31 if (guids.Count > queueSize) 32 { 33 guids.Dequeue(); 34 } 35 } 36 } 37 } 38 }
1 <httpmodules> 2 <add name="RefreshModule" type="Jianyun.RefreshModule.RefreshModule, RefreshModule"> 3 </add></httpmodules>
原创文章,转载请注明: 转载自闲云博客
使用一个HttpModule拦截Http请求,来检测页面刷新(F5或正常的请求)
标签:
原文地址:http://www.cnblogs.com/tianmahygj/p/4235526.html