Visitor Tracker in ASP.NET
ON RecentVisitors
FOR INSERT
AS
BEGIN
— note this will track hits not unique visitors.
select @VisitorsToday = count(*) from RecentVisitors
where dateDiff(day,Date,getdate())=0
and websiteId=@websiteID
delete from AggregatedVisitors where
websiteID = @websiteID
and
Datediff(day,date,getDate())=0
values (@VisitorsToday,@websiteID)
delete from recentVisitors where dateDiff(day,Date,getdate())>1
END
<script language="javascript">
var WebsiteID = 1;
var Tracker = window.document.images["Tracker"];
Tracker.src = "default.aspx?WebsiteId=" + WebsiteID + "&Referrer=" + escape(document.referrer);
</script>
{
string strReferrer = Request.QueryString["Referrer"].ToString();
int intWebsiteID = Convert.ToInt32(Request.QueryString["WebsiteID"]);
string strSQL = "insert into RecentVisitors (IP,Referrer,websiteId) values (";
strSQL += "’" + Request.ServerVariables["REMOTE_ADDR"] + "’,";
strSQL += "’" + strReferrer.Replace("’","”") + "’,";
strSQL += intWebsiteID + ")";
base.ExecuteNonQuery(strSQL);
Session["FirstTime"]=false;
}
Bitmap bmpCanvas = new Bitmap(1,1);
Response.ContentType = "image/gif";
bmpCanvas.Save(Response.OutputStream,ImageFormat.Gif);
ExcecuteNonQuery is a function I wrote to run a statement against the database, and is outside the scope of this blog.
Then, to view this data in a meaningful way, I created a page with two dataGrids, dgRecentVisitors and dgAggregatedVisitors, which used the following SQL to display their results:
select top 20 rv.id,referrer,date from recentvisitors rv
join websites w on w.id = rv.websiteid
where charindex(w.websiteaddress,rv.referrer)=0
order by date desc
and
select * from aggregatedVisitors order by date desc.
and, that suffices for a tracker for my purposes, and I have access to the raw data, should I need to run queries to work out sales conversion rates etc. The only downfall is that it does not correctly measure visitors rather than hits, but that’s work for another day.
Njoy.
Reconnecting ADSL programatically
http://192.168.1.2/doc/loginout.htm?
WINDWEB_URL = %2Fdoc%2Floginout.htm&
simple_ppp_username = xxxx&
simple_ppp_pwd = xxxx&
wanAdapterSelection = 0&
wan_encapsulation = 0&
wan_VPI = 0&
wan_VCI = 38&
PPP_connection_number = 1&
New_PPP_Action = 0
VPN option greyed out in Windows XP
Parser Error Message: Access is denied
at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Boolean isStringized, Evidence assemblySecurity, Boolean throwOnFileNotFound, Assembly locationHint, StackCrawlMark& stackMark)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Boolean stringized, Evidence assemblySecurity, StackCrawlMark& stackMark)
at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark)
at System.Reflection.Assembly.Load(String assemblyString)
at System.Web.UI.CompilationConfiguration.LoadAssemblies(Hashtable original)
[ConfigurationException]: Access is denied: ‘erc’. (c:winntmicrosoft.netframeworkv1.1.4322Configmachine.config line 258)
at System.Web.UI.CompilationConfiguration.LoadAssemblies(Hashtable original)
at System.Web.UI.TemplateParser.AppendConfigAssemblies()
at System.Web.UI.TemplateParser.PrepareParse()
at System.Web.UI.TemplateParser.Parse()
at System.Web.UI.TemplateParser.GetParserCacheItemThroughCompilation()
at System.Web.UI.TemplateParser.GetParserCacheItemInternal(Boolean fCreateIfNotFound)
at System.Web.UI.TemplateParser.GetParserCacheItemWithNewConfigPath()
at System.Web.UI.TemplateParser.GetParserCacheItem()
at System.Web.UI.ApplicationFileParser.GetCompiledApplicationType(String inputFile, HttpContext context, ApplicationFileParser& parser)
at System.Web.HttpApplicationFactory.CompileApplication(HttpContext context)
at System.Web.HttpApplicationFactory.Init(HttpContext context)
at System.Web.HttpApplicationFactory.GetApplicationInstance(HttpContext context)
at System.Web.HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr)
Using DBCC to create fair performance tests on stored procedures
Full text catalog not populating on SQL server 2005
IFrames and the back button
graph.src = ‘someurl’
var wasGraphLoaded = false;
setTimeout(‘checkGraph()’,500);
function checkGraph()
{
if (imgGraph.document.body.innerHTML.indexOf("…")==-1)
{
// Graph must be loaded…
wasGraphLoaded = true;
}
else
{
// Graph isn’t loaded.
if (wasGraphLoaded)
{
// The back button bust have been pressed
window.history.go(-1);
}
}
setTimeout(‘checkGraph()’,500);
}
Redistributing a VB6 application the “Free way”
Workaround for Bitmap ColorDepth in C#
Image imgTIFF = Image.FromStream(s);
ImageCodecInfo ici = GetEncoderInfo("TIFF");
EncoderParameter ep =
new EncoderParameter(Encoder.ColorDepth,24L);EncoderParameters eps =
new EncoderParameters(1);eps.Param[0]= ep;
imgTIFF.Save(@"c:test.tiff",ici,eps);
Image imgBMP = Image.FromFile(@"c:test.tiff");
imgBMP.Save(@"c:test.bmp");
private
ImageCodecInfo GetEncoderInfo(string mimeType){
ImageCodecInfo[] encs = ImageCodecInfo.GetImageEncoders();
for (int ix = 0; ix <= encs.Length; ix++){
if ( encs[ix].CodecName.IndexOf(mimeType) != -1){
return encs[ix];}
}
return null;}
Converting a Bitmap to a pixel array
{
public byte red;
public byte green;
public byte blue;
}
then I read it using some Unsafe code thus:
public pixel[,] BitmapToArray(Bitmap b)
{
pixel[,] bmpData=new pixel[b.Width,b.Height];
// GDI+ still lies to us – the return format is BGR, NOT RGB.
BitmapData bmData = b.LockBits(new Rectangle(0, 0, b.Width, b.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
int stride = bmData.Stride;
System.IntPtr Scan0 = bmData.Scan0;
unsafe
{
byte * p = (byte *)(void *)Scan0;
int nOffset = stride – b.Width*3;
int nWidth = b.Width * 3;
for(int y=0;y<b.Height;++y)
{
for(int x=0; x < nWidth; ++x )
{
switch(x%3)
{
case 0:
bmpData[x/3,y] =
new pixel();
bmpData[x/3,y].blue = (
byte)(p[0]);
break;
case 1:
bmpData[x/3,y].green = (
byte)(p[0]);
break;
case 2:
bmpData[x/3,y].red = (byte)(p[0]);
break;
}
++p;
}
p += nOffset;
}
}
b.UnlockBits(bmData);
return bmpData;
}