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.
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>