Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从服务器返回跟踪像素时检测_Javascript_Asp.net - Fatal编程技术网

Javascript 从服务器返回跟踪像素时检测

Javascript 从服务器返回跟踪像素时检测,javascript,asp.net,Javascript,Asp.net,客户使用一项服务,从我的服务器安装脚本javascript。我有一个跟踪像素插入到页面上通过脚本,拿起点击信息 当asp.net服务器截取pixel.aspx时,它会将假图像查询字符串中的登录信息插入数据库,并返回pixel.gif…所有这些都能正常工作,请参见下文 Imports Microsoft.VisualBasic Imports System.Web Public Class HelloWorldModule Implements IHttpModule Private patte

客户使用一项服务,从我的服务器安装脚本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

我从来没有找到可以识别图像src的东西,因为服务器在页面呈现之前发送了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
' 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