2015-04-29 2 views
0

Клиенты используют службу, где они устанавливают скрипт (javascript) с моего сервера. У меня есть пиксель отслеживания, вставленный на страницу через скрипт, который собирает информацию об щелчке.Обнаруживать, когда пиксель отслеживания возвращается с сервера

Когда сервер asp.net перехватывает pixel.aspx, он вставляет данные входа из строки запроса фальшивого изображения в базу данных и возвращает pixel.gif ... все это отлично работает (см. Ниже).

Imports Microsoft.VisualBasic 
Imports System.Web 

Public Class HelloWorldModule 
Implements IHttpModule 
Private pattern As String = "/images/(?<key>.*)\.aspx" 
Private logoFile As String = "~/images/pixel.gif" 

Public Sub New() 
End Sub 

Public ReadOnly Property ModuleName() As String 
    Get 
     Return "HelloWorldModule" 
    End Get 
End Property 

' In the Init function, register for HttpApplication 
' events by adding your handlers. 
Public Sub Init(ByVal application As HttpApplication) Implements IHttpModule.Init 
    AddHandler application.BeginRequest, AddressOf GetImage_BeginRequest 
End Sub 

Public Sub GetImage_BeginRequest(ByVal sender As Object, ByVal args As System.EventArgs) 
    'cast the sender to a HttpApplication object 
    Dim application As System.Web.HttpApplication = CType(sender, System.Web.HttpApplication) 

    Dim url As String = application.Request.Path 'get the url path 
    'create the regex to match for becon images 
    Dim r As New Regex(pattern, RegexOptions.Compiled Or RegexOptions.IgnoreCase) 
    If r.IsMatch(url) Then 
     Dim mc As MatchCollection = r.Matches(url) 
     If Not (mc Is Nothing) And mc.Count > 0 Then 
      Dim key As String = mc(0).Groups("key").Value 
      'SaveToDB(key) 
     End If 

     'now send the image to the client 
     application.Response.ContentType = "image/gif" 
     application.Response.WriteFile(application.Request.MapPath(logoFile)) 
     application.Response.End() 
    End If 
End Sub 'GetImage_BeginRequest 

Если клиент, который работает этот сценарий имеет просроченный счет, я хочу, чтобы вернуть error.gif в ответ (вместо pixel.gif), а затем мне нужно обнаружить error.gif SRC, так что я не может сообщить клиенту, что срок службы истек.

Я пробовал следующее, но он возвращает исходный src изображения. Как определить обновленный src изображения?

Любая помощь или предложения будут оценены.

testImage("images/pixel.aspx?login=123&country=canada", function (url, result) { if (result === 'success') { console.log(url) } }, 10000); 

    function testImage(url, callback, timeout) { 
     timeout = timeout || 5000; 
     var timedOut = false, timer; 
     var img = new Image(); 
     img.onerror = img.onabort = function() { 
      if (!timedOut) { 
       clearTimeout(timer); 
       callback(url, "error"); 
      } 
     }; 
     img.onload = function() { 
      if (!timedOut) { 
       clearTimeout(timer); 
       callback(url, "success"); 
       console.log(checkURL(url)) 
      } 
     }; 
     img.src = url; 
     document.body.appendChild(img); 

     timer = setTimeout(function() { 
      timedOut = true; 
      callback(url, "timeout"); 
     }, timeout); 
    } 

function checkURL(url) { 
     return (url.match(/\.(jpeg|jpg|gif|png)$/) != null); 
    } 

ответ

0

Я никогда не нашел то, что может идентифицировать СРК изображения, из-за сервера, отправившего pixel.gif до страницы оказанной так ни один скрипт не мог обнаружить изменение Src. Я поставил логику на сервере, так что, когда истечет срок действия учетной записи клиента, теперь я показываю сообщение на запрашивающей веб-странице истечения срока действия счета ...

' In the Init function, register for HttpApplication 
' events by adding your handlers. 
Public Sub Init(ByVal application As HttpApplication) Implements IHttpModule.Init 
    If acct_expired = False Then 
     AddHandler application.BeginRequest, AddressOf GetImage_BeginRequest 
    Else 
     AddHandler application.BeginRequest, AddressOf Application_BeginRequest ' GetImage_BeginRequest 
    End If 

End Sub 

Public Sub GetImage_BeginRequest(ByVal sender As Object, ByVal args As System.EventArgs) 
    'cast the sender to a HttpApplication object 
    Dim application As System.Web.HttpApplication = CType(sender, System.Web.HttpApplication) 

    Dim url As String = application.Request.Path 'get the url path 
    'create the regex to match for becon images 
    Dim r As New Regex(pattern, RegexOptions.Compiled Or RegexOptions.IgnoreCase) 
    If r.IsMatch(url) Then 
     Dim mc As MatchCollection = r.Matches(url) 
     If Not (mc Is Nothing) And mc.Count > 0 Then 
      Dim key As String = mc(0).Groups("key").Value 
      'SaveToDB(key) 
     End If 

     'now send the image to the client 
     application.Response.ContentType = "image/gif" 
     application.Response.WriteFile(application.Request.MapPath(logoFile)) 
     application.Response.End() 

    End If 
End Sub 'GetImage_BeginRequest 

Private Sub Application_BeginRequest(ByVal source As Object, _ 
     ByVal e As EventArgs) 
    ' Create HttpApplication and HttpContext objects to access 
    ' request and response properties. 
    Dim application As HttpApplication = DirectCast(source, HttpApplication) 
    Dim context As HttpContext = application.Context 
    Dim filePath As String = context.Request.FilePath 
    Dim fileExtension As String = VirtualPathUtility.GetExtension(filePath) 
    context.Response.Write("<hr><h1><font color=red>Your account has expired. Upgrade Today!</font></h1>") 
End Sub 
Смежные вопросы