2015-10-06 66 views
-1

我查了很多其他示例,无法完全找到我要找的内容,有点背景。我正在研究解决方案以防止浏览器窗口打开。.ASPX已更改检查

当查看目标URL时,标题始终是相同的,直到页面中的JavaScript能够查看是否已发布新消息。在这一点上,动态更改的基础是,如果您的页面处于活动状态,并且未点击确认按钮,则java脚本会将其更改为无新消息。

我最终的目标是检查一个.ASPX文件的网站,它需要进行身份验证才能查看它。我试过这段代码来检查文件的大小,希望能够检测到所有大小的变化,但是当没有真正的更新时,它的查找大小变为频繁变化。

任何想法?

long bbssize = 0; // start size. 
long bbssizewas = 0; // start size. 

在转瞬间包裹...

HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://www.fictionalsite.com/Main_View.aspx"); 
req.Method = "HEAD"; 
req.Credentials = CredentialCache.DefaultCredentials; 
HttpWebResponse resp = (HttpWebResponse)(req.GetResponse()); 
long lenth = resp.ContentLength; 
bbssize = lenth; 
if (bbssize != bbssizewas) // checks for change. 
{ 
    pictureBox1.BackColor = Color.Lime; // changes color to green. 
    bbssizewas = bbssize; // sets new value to check. 
} 
+2

投票下来,直到你写出有意义的英文文本。 – Dusan

回答

1

我找到了原因,我的剧本是工作不正确,在.aspx的位置是在字节波动每隔几秒钟,约11使它看起来像有是一个变化。

我调整了代码以添加“字节”来解释它,导致if语句仅在发生重大更改时才跳闸。

//在项目早期口述......

long timerisat = 0; 
    long timerwas = 0; 

//装在一个时钟滴答。

  System.Net.WebClient client = new System.Net.WebClient(); 
      client.Credentials = CredentialCache.DefaultCredentials; 
      client.OpenRead("http://example.com/thewebpage.aspx"); 
      Int64 bytes_total = Convert.ToInt64(client.ResponseHeaders["Content-Length"]); 
      timerisat = bytes_total; 

      if (timerisat > timerwas) // checks for change. 
      { 
       pictureBox1.BackColor = Color.DarkRed; // changes color to green. 
       button7.FlatAppearance.BorderColor = Color.Red; 
       timerwas = timerisat + 20; // sets new value to check. (adds 20 bytes)   
       // Notification pops up on tooltip. 
       this.notifyIcon1.BalloonTipText = "MyTSC Bulletin Board - Updated"; 
       this.notifyIcon1.BalloonTipTitle = "Workspace"; 
       this.notifyIcon1.Visible = true; 
       this.notifyIcon1.ShowBalloonTip(10); 
      } 
相关问题