3

Trying to record "Page Loads" for custom CMS. On page load, I invoke a CFC that saves page and user information. Works on interior pages but not Homepage.

Every "Homepage Click" records a "visit" to the homepage and then immediately records a link from the homepage to 404 Error. This means that the 404 Page is being loaded (in the background?) and firing the CFC. The verification of this is what is saved in the database. I have no idea how this is happening.

I have researched several posts here - trying varied approaches: I have tried removing all includes - this did not fix it. I have tried IIS Mappings - removing all rewrites and redirects - (from /index.cfm to /) - and this did not fix it.

enter image description here

Code as follows:`

        <cfinvoke
        Component="components.Page_Count"
        Method="RecordPageView"
        PageID="0"
        Title="Homepage"
        LinkName="/index.cfm"
        IPAddress="#cgi.remote_addr#"
        ThisUserAgent="#CGI.HTTP_USER_AGENT#"
        Returnvariable="PageLinkRecorded"
        >

CFC Code:

<cffunction 
    name="RecordPageView" 
    access="public" 
    returntype="any">
        <cfargument name="PageID" type="string" required="no">
        <cfargument name="Title" type="string" required="no">
        <cfargument name="LinkName" type="string" required="no">
        <cfargument name="IPAddress" type="string" required="no">
        <cfargument name="ThisUserAgent" type="string" required="no">

        <cfparam name="var.ESID" default="">
        <cfparam name="var.CookieID" default="0">
        <cfparam name="var.Referer" default="">
        <cfparam name="var.VisitDate" default="#Now()#">
        <cfparam name="var.IPAddress" default="#cgi.remote_addr#">
        <cfparam name="var.IsThisABot" default="FALSE">

    <cfif arguments.Title NEQ "">

        <cfset variables.MyCookieName = Application.CompanyName>
        <!--- remove ALL Special Characters --->
        <cfset variables.MyCookieName = "#REReplace(variables.MyCookieName,"[^0-9A-Za-z ]","","all")#" />

        <!--- remove ALL spaces from the string --->
        <cfset variables.MyCookieName = ReReplace(variables.MyCookieName, "[[:space:]]","","ALL")>


        <cfif isDefined("COOKIE.#variables.MyCookieName#_UUID") AND Evaluate("COOKIE.#variables.MyCookieName#_UUID") NEQ "">
            <cfset VAR.CookieID = Evaluate("COOKIE.#variables.MyCookieName#_UUID")>
        <cfelse>
            <cfset VAR.CookieID = CreateUUID()>
            <cfcookie name="#variables.MyCookieName#_UUID" value="#VAR.CookieID#" expires="NEVER" />
        </cfif>

        <cfif Len(arguments.ThisUserAgent) GT 0>
            <cfloop list="bot\b,crawl,\brss,feed,news,blog,reader,syndication,coldfusion,slurp,google,zyborg,emonitor,jeeves,Googlebot,Google,duckduckbot,Baiduspider,YandexBot,exabot,Sogou,facebot,facebookexternalhit,ia_archiver" index="bot" delimiters=",">
                <cfif FindNoCase(bot, arguments.ThisUserAgent)>
                    <cfset VAR.IsThisABot="TRUE" />
                <cfelse>
                    <cfset VAR.IsThisABot="FALSE" />
                </cfif>
            </cfloop>
        <cfelse>
            <cfset VAR.IsThisABot="TRUE" />
        </cfif>


        <cfif IsDefined("SESSION.Auth.ESID")>
            <cfset var.ESID = SESSION.Auth.ESID>
        </cfif>

        <cfif IsDefined("CGI.script_name")>
            <cfset var.ThisPage = CGI.script_name>
        </cfif>


        <cfif IsDefined("CGI.http_referer") AND CGI.http_referer NEQ "">
            <cfset var.Referer = CGI.http_referer>
                <cfif FindNoCase(".css", CGI.http_referer)>
                    <cfset VAR.IsThisABot="TRUE">
                </cfif>
        <cfelse>
            <cfset var.Referer = CGI.QUERY_STRING>
        </cfif>


            <cfif VAR.IsThisABot EQ "FALSE">

                    <cfquery datasource="#Application.DSN#" username="#Application.username#" password="#Application.password#" result="CountSaved">
                        INSERT INTO content_track (PageID,PageTitle,LinkName,ESID,CookieID,Referer,IPAddress) 
                        VALUES (
                        <cfif arguments.PageID NEQ "">
                            <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.PageID#">
                        <cfelse>
                            0
                        </cfif>
                        ,
                        <cfif arguments.Title NEQ "">
                            <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.Title#">
                        <cfelse>
                            NULL
                        </cfif>
                        ,
                        <cfif arguments.LinkName NEQ "">
                            <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.LinkName#">
                        <cfelse>
                            NULL
                        </cfif>
                        ,
                        <cfif var.ESID NEQ "">
                            <cfqueryparam cfsqltype="cf_sql_integer" value="#var.ESID#">
                        <cfelse>
                            0
                        </cfif>
                        ,
                        <cfif var.CookieID NEQ "">
                            <cfqueryparam cfsqltype="cf_sql_varchar" value="#var.CookieID#">
                        <cfelse>
                            0
                        </cfif>
                        ,
                        <cfif var.Referer NEQ "">
                            <cfqueryparam cfsqltype="cf_sql_varchar" value="#var.Referer#">
                        <cfelse>
                            NULL
                        </cfif>
                        ,
                        <cfif var.IPAddress NEQ "">
                            <cfqueryparam cfsqltype="cf_sql_varchar" value="#var.IPAddress#">
                        <cfelse>
                            NULL
                        </cfif>
                        )
                    </cfquery>

                </cfif>
    </cfif>
            
    <cfset PageRecorded = VAR>
            
    <cfreturn PageRecorded>
</cffunction>

My IIS Rules

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
    <directoryBrowse enabled="false" />
    <urlCompression doStaticCompression="true" doDynamicCompression="true" />
    
<rewrite>
<rules>

    <rule name="RedirectWwwToNonWww" stopProcessing="false">
      <match url="(.*)" />
      
      <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" />
      </conditions>
      
      <action type="Redirect" url="https://{C:2}{REQUEST_URI}" redirectType="Permanent" />
    </rule>
    
    
   <rule name="Imported Rule 1" stopProcessing="true">
    <match url="index.cfm" ignoreCase="true" />
    <conditions logicalGrouping="MatchAny">
      <add input="{URL}" pattern="^.*\.(cfm|cfc|css|gif|png|jpg|jpeg|js|svg)$" negate="true" /> 
    </conditions>
    <action type="Rewrite" url="/" />
   </rule>
    
    
    
    
   <rule name="HTTP to HTTPS redirect" stopProcessing="true"> 
     <match url="(.*)" /> 
     <conditions> 
       <add input="{HTTPS}" pattern="off" ignoreCase="true" />
     </conditions> 
     <action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />
   </rule> 
</rules>
</rewrite>
    <security>
        <requestFiltering>
            <fileExtensions>
                <add fileExtension=".pl" allowed="false" />
            </fileExtensions>
        </requestFiltering>
    </security>
    <httpErrors errorMode="DetailedLocalOnly">
        <remove statusCode="404" subStatusCode="-1" />
        <error statusCode="404" subStatusCode="-1" prefixLanguageFilePath="" path="/Content/404-Error.cfm" responseMode="ExecuteURL" />
    </httpErrors>
    <staticContent>
        <remove fileExtension=".scss" />
        <mimeMap fileExtension=".scss" mimeType="text/css" />
    </staticContent>
    
</system.webServer>
</configuration>
  • 1
    Check the network traffic using your browser's dev tools. What does that show you? You should see the 404 there and then be able to determine which request is causing it. Check the request tab on that 404 request. – Miguel-F Feb 16 '22 at 18:13
  • I tried that too - I am not seeing anything there. All elements are Status 200. And there aren't any ajax requests on that page either. I even went so far as removing all includes and module tags from the page... It still creates the phantom 404 Load. That is what made me look into the IIS rewriting. However, when I removed all rewrites and redirects, it still loads the 404. My guess is that it is happening at the server level (because it is not rendered to the user) - but I don't know what that would/could be. – Big Fat Designs Feb 16 '22 at 22:19
  • You can use failed request tracking to view detailed error information about 404 error. – samwu Feb 17 '22 at 08:35
  • Is your ColdFusion server configured to return HTTP status codes? Is the setting for `Enable HTTP Status Codes` enabled in your ColdFusion admin. Otherwise ColdFusion will return a 200 status for everything. – Miguel-F Feb 17 '22 at 17:32
  • Also, I don't know if this matters or not but you should not have the attribute `subStatusCode` in your web.config file for the `` definition. You have this ` – Miguel-F Feb 17 '22 at 17:39

0 Answers0